本帖最后由 sinanjj 于 2011-4-30 14:15 编辑
summary
python/pyqt4/QtDesigner helloworld
1, GUI design
create a Main Window, drag-and-drop the widgets(TextEdit, LineEdit, PushButton), layout them.
save to helloworld.ui file.
2, *.ui > *.py
$ pyuic4 helloworld.ui > helloworld.py
3, Writing A Wrapper
run.py
#!/usr/bin/python -d
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui
from helloworld import Ui_MainWindow
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.ui.textEdit.clear)
QtCore.QObject.connect(self.ui.lineEdit, QtCore.SIGNAL("returnPressed()"), self.add_entry)
def add_entry(self):
self.ui.lineEdit.selectAll()
self.ui.lineEdit.cut()
self.ui.textEdit.append("")
self.ui.textEdit.paste()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
setup.py:
from distutils.core import setup
import py2exe
import sys
# If run without args, build executables, in quiet mode.
if len(sys.argv) == 1:
sys.argv.append("py2exe")
sys.argv.append("--includes")
sys.argv.append("sip")
class Target:
def __init__(self, **kw):
self.__dict__.update(kw)
# for the versioninfo resources
self.version = "0.5.0"
self.company_name = "No Company"
self.copyright = "no copyright"
self.name = "py2exe sample files"
test = Target(
# used for the versioninfo resource
description = "A sample GUI app",
# what to build
script = "run.py",
#~ other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="test_wx"))],
#icon_resources = [(1, "editra.ico")]
#~ dest_base = "test_wx"
)
setup(
# The first three parameters are not required, if at least a
# 'version' is given, then a versioninfo resource is built from
# them and added to the executables.
#~ version = "0.5.0",
#~ description = "py2exe sample script",
#~ name = "py2exe samples",
# targets to build
windows = [test]
#~ console = ["hello.py"],
) |