本文讲述用QtDesigner创建GUI,通过PyQt4转化为可执行的Python文件
1. QtDesigner创建一个GUI后会生成一个 .ui文件 (eg: TestUI.ui)
2. 通过命令 Python pyuic.py -o TestUI.py TestUI.ui 生成我们需要的py文件(TestUI.py)
3. 创建一个 Test.py 文件,编辑以下代码:
1 import sys 2 from PyQt4.QtGui import * 3 from PyQt4.QtCore import * 4 import TestUI 5 6 class uitest( QMainWindow,TestUI.Ui_MainWindow): 7 def __init__(self, parent=None): 8 super(uitest, self).__init__(parent) 9 self.setupUi(self) 10 11 app = QApplication(sys.argv) 12 w = uitest() 13 w.show() 14 app.exec_()
4. Python Test.py 即可得到步骤1中设计的GUI
注: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).
原文:http://www.cnblogs.com/njuptlwh/p/7426898.html