python26UI[PySide之helloworld]
时间:2011-03-29 来源:iTech
PySide
website : http://www.pyside.org/
onlinedoc :http://www.pyside.org/docs/pyside/
wiki:http://developer.qt.nokia.com/wiki/PySideDocumentation/
sourcecode:http://qt.gitorious.org/pyside/
example :http://qt.gitorious.org/pyside/pyside-examples/trees/master
The PySide project provides LGPL-licensed Python bindings for the Qt cross-platform application and UI framework, as well as a complete toolchain for rapidly generating bindings for any Qt-based C++ class hierarchies. PySide Qt bindings allow both free open source and proprietary software development and ultimately aim to support all of the platforms as Qt itself.
一 安装python和pyside
python2.6 win32 :http://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
PySide win32 :http://pypi.python.org/packages/2.6/P/PySide/PySide-1.0.0qt472.win32-py2.6.exe
二 简单实例
代码:
# Import PySide classes
import sys
from PySide.QtCore import *
from PySide.QtGui import *
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.setWindowTitle("iTech's Blog")
# Create widgets
self.edit = QLineEdit("Write your name here")
self.button = QPushButton("Welcome to my blog")
# Create layout and add widgets
layout = QVBoxLayout()
layout.addWidget(self.edit)
layout.addWidget(self.button)
# Set dialog layout
self.setLayout(layout)
# Add button signal to welcome slot
self.button.clicked.connect(self.welcome)
# Welcome to the user
def welcome(self):
print ("%s, Welcome to my blog[http://itech.cnblogs.com]! " % self.edit.text())
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = Form()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())
结果:
三 更多 examples
下载所有的examples(http://qt.gitorious.org/pyside/pyside-examples/trees/master ),然后解压到C:\Python26\pyside-pyside-examples。
执行C:\Python26\pyside-pyside-examples\examples\demos\qtdemo> python qtdemo.py 来查看所有的demo。 如下图:
参考:
PyQT : http://www.riverbankcomputing.co.uk/news
完!