1. 挑選 GUI設計程序: wxPython Vs. pyQt4
html
參考連接:http://www.douban.com/group/topic/14590751/python
(1):wxWidgets wxPython :開發商業軟件徹底沒有問題,使用LGPL協議;前提是你不能對這個庫的自己有什麼改動,若是有改動的話,你要開放你改動的那部分代碼。
若是你只是使用這些庫的話,沒什麼問題,不要對庫自己的代碼進行改動。
c++
Q: 最近看一個wxpython的項目代碼,想找個文檔,難死了,基本沒有,函數用法基本沒有,類的用法說明沒有; A: 文檔應該寫在源代碼裏了吧?就像tornado,或者像emacs的插件同樣。程序員
拋開wx自身不談,wxpython移植的很是爛,文檔一坨屎,就是robin本身沒事維護一下,搞很差哪天就玩完。PyQt還算個產品的樣子。買了本wxPython in Action ,剛看完。如今能夠寫一些小工具了。
編程
A:Like Python and wxWidgets, wxPython is Open Source which means that it is free for anyone to use and the source code is available for anyone to look at and modify.
windows
(2):pyQt4:pyQt4運行速度更快,寫一樣的程序代碼量應該比wxpython少的多,pyQt如今也有LGPL版了,諾基亞的pyside,就是不知道穩定性怎麼樣,打包比wxpython大一點,一個helloworld小窗口,wxpython用py2exe打包壓縮後2M多一點,pyQt打包壓縮後8M左右。app
OxFAN 是能夠連接,但只能動態連接,並且發行時不能綁定LGPL軟件的二進制文件,好比安裝包中不能含有QT的二進制文件(若是使用LGPL協議的話);編程語言
推薦使用NOKIA QT 的官方 LGPL 協議版本——PySide;ide
2. PyQt4:Qt庫的Python綁定PyQt函數
Q : 爲何使用PyQt4: A: 權衡
PyQt向Python程序員提供了使用完整Qt應用程序接口的方法。您幾乎能夠用Python作任何C++能作的事。
既然是應用程序接口,用C++或是Python都是同樣的。因而「爲何我得使用它」這個問題就能夠歸結爲編程語言的選擇上,而不必定要用PyQt。對我來 說做爲一種編程語言,python相對於c++的優勢是在編程效率上。您能夠看到標準的Qt例子移植到PyQt後的代碼。它們具備相同的功能,使用相同的 應用程序接口,但Python版的代碼只有原來的50-60%,並且它們更容易閱讀。
與編程效率相關的是Python更容易學習,並且它足以知足富有經驗的程序員。奇趣公司已經發現PyQt可使他們嚮應用高端技術的團體出售Qt,這些團體的成員是工業專家(化學家,航空工程師等)而不是精深的C++程序員。
固然PyQt既成熟又穩定,而且有龐大的用戶羣體。我從用戶那兒獲得的兩個最普通的反饋是「它恰到好處"和「它很不錯。」
3.使用QT設計UI:
用qt設計師設計ui文件:
4. 使用QT設計UI,編譯生成Python工程:
參考連接:http://www.cnblogs.com/fickleness/p/3145967.html
編譯已經生成的用qt設計師保存的UI文件,使用命令pyuic4
C:\Users\Administrator>cd C:\Python27\Lib\site-packages\PyQt4 C:\Python27\Lib\site-packages\PyQt4>pyuic4 C:\Python27\Lib\site-packages\PyQt4\d emo.ui -o C:\Python27\Lib\site-packages\PyQt4\demo.py
(在DOS環境下編譯 : ( 小插曲,進dos找不到 python命令, 想起來上次配置環境變量是 保存在administrater的變量中了,只能在本次生效,要想一直生效就得保存路徑名
) 編譯生成demo.ui--------------- demo.py文件在工程中import filesystem,要不程序怎麼知道要使用demo.py!
導入成功。
使用模塊代碼顯示:
import sys from PyQt4 import QtGui,QtCore from demo import * if __name__ == "__main__": app =QtGui.QApplication(sys.argv) mywidget = Ui_MainWindow() #you need use the class name in PyQtSampleinstead form = QtGui.QMainWindow() mywidget.setupUi(form) form.show() app.exec_()以測試方式運行:參考連接:http://blog.csdn.net/lainegates/article/details/8774410
class UItest(QtGui.QMainWindow): def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.loginGui() def loginGui(self): self.ui = Ui_Dialog() self.ui.setupUi(self) self.show() app = QtGui.QApplication(sys.argv) myqq = UItest() sys.exit(app.exec_())(注:pyuic參數說明:
NAME pyuic4 - compile Qt4 user interfaces to Python code SYNOPSIS pyuic4 [OPTION]... FILE DESCRIPTION pyuic4 takes a Qt4 user interface description file and compiles it to Python code. It can also show a preview of the user interface. OPTIONS -h, --help Show a summary of the options. --version Display the version number of pyuic4 of the version of Qt which PyQt4 was generated for. -p, --preview Show a preview of the UI instead of generating Python code. -o, --output=FILE Write the generated Python code to FILE instead of stdout. -d, --debug Show detailed debugging information about the UI generation process. -x, --execute Generate extra code to test and display the class when executed as a script. -i, --indent=NUM Set the indentation width to NUM spaces. A TAB character will be used if NUM is 0 (default: 4). )
run 工程便可實現,不過邏輯設計尚未完成,期待原做者繼續!
4. 使用py2exe生成win軟件:
參考文章:http://www.cnblogs.com/jans2002/archive/2006/09/30/519393.html
py2exe是一種python發佈工具,能夠把python腳本轉換成windows下的可執行程序,不須要安裝python即可運行。
py2exe如今能夠用來建立使用了wxPython, Tkinter, Pmw, PyGTK, pygame, win32com client and server 等模塊的程序。
詳細介紹能夠看它的官方網站 http://starship.python.net/crew/theller/py2exe/
1、簡介
py2exe是一個將python腳本轉換成windows上的可獨立執行的可執行程序(*.exe)的工具,這樣,你就能夠不用裝python而在windows系統上運行這個可執行程序。
py2exe已經被用於建立wxPython,Tkinter,Pmw,PyGTK,pygame,win32com client和server,和其它的獨立程序。py2exe是發佈在開源許可證下的。
二:個人過程:
set PATH=%PATH%;C:\Python27 //set path! cd d/ D:\ cd D:\Develope\EclipseWorks\PythonGUI
在CMD欄裏,運行命令 python setup.py py2exe
可在目錄下生成 dist/xxx.exe 能夠運行
注:對於使用pyQT4 產生:
Traceback (most recent call last): File "_init_.py", line 2, in <module> File "PyQt4\QtGui.pyc", line 12, in <module> File "PyQt4\QtGui.pyc", line 10, in __load ImportError: No module named sip
setup.py裏面添加:
windows = [{"script":"_init_.py"} ], options={"py2exe":{"includes":["sip"]}} 便可
3、py2exe的用法
若是你有一個名爲helloworld.py的python腳本,你想把它轉換爲運行在windows上的可執行程序,並運行在沒有安裝python的windows系統上,那麼首先你應寫一個用於發佈程序的設置腳本例如mysetup.py,在其中的setup函數前插入語句import py2exe 。
mysetup.py示例以下:
# mysetup.py from distutils.core import setup import py2exe
python mysetup.py py2exe --help
4、指定額外的文件
一些應用程序在運行時須要額外的文件,諸如配置文件、字體、位圖。
若是在安裝腳本中用data_files可選項指定了那些額外的文件,那麼py2exe能將這些文件拷貝到dist子目錄中。data_files應包含一個元組(target-dir, files)列表,其中的files是這些額外的文件的列表。
示例以下:
# mysetup.py from distutils.core import setup import glob import py2exe setup(console=["helloworld.py"], data_files=[("bitmaps", ["bm/large.gif", "bm/small.gif"]), ("fonts", glob.glob("fonts\\*.fnt"))], )說明:data_files選項將建立一個子目錄dist\bitmaps,其中包含兩個.gif文件;一個子目錄dist\fonts,其中包含了全部的.fnt文件。
# mysetup.py from distutils.core import setup import py2exe setup(service=["MyService"])所建造的可執行的service是能夠經過在其後跟必定的命令行參數標記來自行安裝和卸載的。你能夠經過在這個可執行的service(exe)後跟一-help參數來獲得更多的幫助。
6、COM servers
你能夠經過傳遞一個com_server 關鍵字參數給setup函數來建造Windows NT services
,這個service參數的值必須是一個Python模塊名(包含一個或多個COM server 類)的列表。
示例以下:
# mysetup.py from distutils.core import setup import py2exe