我开始使用Python中的GTK 3。如何使用PyInstaller、cx_Freeze或py2exe从我的GTK 3 Python源代码创建可执行Windows文件?
我尝试了很多Stack Overflow和其他网页上的答案,但都没有成功。
我尝试使用PyInstaller制作它(我认为这可能是最简单的方法),我的源代码如下:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class ButtonWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Button Demo")
self.set_border_width(10)
hbox = Gtk.Box(spacing=6)
self.add(hbox)
button = Gtk.Button.new_with_label("Click Me")
button.connect("clicked", self.on_click_me_clicked)
hbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("_Open")
button.connect("clicked", self.on_open_clicked)
hbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("_Close")
button.connect("clicked", self.on_close_clicked)
hbox.pack_start(button, True, True, 0)
def on_click_me_clicked(self, button):
print("\"Click me\" button was clicked")
def on_open_clicked(self, button):
print("\"Open\" button was clicked")
def on_close_clicked(self, button):
print("Closing application")
Gtk.main_quit()
win = ButtonWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
但是我得到了以下错误:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "c:\python34\lib\gi\__init__.py", line 102, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gtk not available
gtk returned -1
我该怎么办或者如何使用py2exe或cx_Freeze制作可执行文件?