Python随笔(PySide)

# 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("cnblogs'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://www.cnblogs.com/thetung/]! " % 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_())

 

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 (看了example后一切就都太简单了)

 

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://qt-project.org/wiki/PySide_Binaries_Windows

 

二 简单实例

代码:

 

 结果:

三 更多 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

Rapid.GUI.Programming.with.Python.and.Qt.Oct.2007
posted @ 2013-10-27 14:41  thetung  阅读(988)  评论(0编辑  收藏  举报