PySide requires Python 2.6 or later and Qt 4.6 or better so I used python3.4.
Can you read more about PySide from pypi.python.org/pypi/PySide:
PySide is the Python Qt bindings project, providing access to the complete Qt 4.8 framework as well as to generator tools for rapidly generating bindings for any C++ libraries.
You can use pip3.4 to install this module:
1 2 3 4 5 6 | C:\Python34\Scripts>pip3.4.exe install pyside Collecting pyside Downloading PySide-1.2.2-cp34-none-win_amd64.whl (43.3MB) 100% |################################| 43.3MB 4.2kB/s Installing collected packages: pyside Successfully installed pyside-1.2.2 |
Now I can some simple examples to see how to deal with this python module.
The code example is very simplistic if you know something about Qt. Even you can deal with this tutorial.
1 2 3 4 5 6 7 8 9 10 11 | import sys from PySide import QtGui app = QtGui.QApplication(sys.argv) wid = QtGui.QWidget() wid.resize(250, 150) wid.setWindowTitle('Simple') wid.show() sys.exit(app.exec_()) |
The next example will show you a message box with two buttons.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | # -*- coding: utf-8 -*- import sys from PySide import QtGui class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): self.resize(250, 150) self.center() self.setWindowTitle('Center') self.show() def center(self): qr = self.frameGeometry() cp = QtGui.QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def closeEvent(self, event): reply = QtGui.QMessageBox.question(self, 'Message', "Are you sure to quit?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: event.accept() else: event.ignore() def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main() |