1.安装pygtk及gtk运行时库(run time library)
我所选择的安装版本是
python 2.5.2 (下载地址 http://www.python.org/ )
python gtk+ (下载地址 http://www.pygtk.org/downloads.html )
PyCairo http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/1.4/pycairo-1.4.12-2.win32-py2.6.exe
PyGObject http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/2.14/pygobject-2.14.2-2.win32-py2.6.exe
PyGTK http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.12/pygtk-2.12.1-3.win32-py2.6.exe
以上就是python开发gtk+必需的三个python包,虽说是py2.6结尾(意思是支持python 2.6,但是也支持python 2.5~~)
python gtk+的官网与资源 http://www.pygtk.org
重要的第二步就是GTK+运行时库了!
GTK+运行时库 http://www.gtk.org/download-windows.html#StableRelease
这一步也会让人迷惑,有太多的包选择了!
全部下载太麻烦了!
所有有一个 bundle打包下载全部的gtk+运行时库
http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.16/gtk+-bundle_2.16.6-20091013_win32.zip
这个包的大小是27M多!
我把python gtk+所依整的所有动态库都取出来,做了一个小小的包,下载4M就可以了!
及其python安装包全部打包
下载地址为
http://download.csdn.net/source/1890041
2.配置gtk库为windows path的搜库路径
比较拙的方法是把bundle的bin目录下的所有dll拷贝到system32(不支持这种做法)!
修改windows系统的环境变量,将bundle的bin加入path搜索路径!
如图(我使用的是我抽出来的lib库)
2.pygtk写的"hello workd"
#!/usr/bin/env python """ Simple Hello World example similar to the GTK+ Tutorials one """ import gtk def hello(*args): """ Callback function that is attached to the button """ print "Hello World" window.destroy() def destroy(*args): """ Callback function that is activated when the program is destoyed """ window.hide() gtk.main_quit() # this block creates our main application window window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.connect("destroy", destroy) window.set_border_width(10) # this block creates our button and places it within the window button = gtk.Button("Hello World") # connects the 'hello' function to the clicked signal from the button button.connect("clicked", hello) window.add(button) button.show() # as the button is within the window this also shows the window window.show_all() gtk.main()
运行效果!