- Note: this article is a member of the multipart PySide Newbie Tutorials
English French [qt-devnet.developpez.com] 日本語
About Box
This dialog box shows the version of About Box itself, as well as versions of Qt, PySide and Python beeing used, together with the platform on which the program is being run.
First step is to use Qt Designer to visually design the main window and add one PushButton. We give the name by Saving As the file about.ui (ui extension is added by the Qt Designer).
I saved the about.ui for you in my home pages. You can download it from the following URL and then open it with the Qt Designer to have a look what the GUI looks like at this stage. The source of about.py is also there for your download. Actually, it is always safer to download the original source code than try to get it by copying the display to the clipboard and back to your editor. BTW, I use the highly recommended editor for Python programs, written in Python and Qt, Eric4.
- “The directory with data files for py-simplicissimus examples is at “ http://akabaila.pcug.org.au/pyside-data/
Click on about.ui to download and then view it with Qt Designer at your leisure.
The about.ui is an XML file. If you can not read it, do not let it bother you – Python can not read it, either… To make it readable to python we need to process it with a script from pyside-tools package:
- pyside-uic about.ui > ui_about.py
The Python readable file ui_about.py can now be imported by the program and used as shown in the following code listing
- #!/usr/bin/env python
- # about.py - display about box with info on platform etc.
- import sys
- import platform
- import PySide
- from ui_about import Ui_MainWindow
- __version__ = '0.0.1'
- def __init__(self, parent=None):
- super(MainWindow, self).__init__(parent)
- self.setupUi(self)
- self.aboutButton.clicked.connect(self.about)
- def about(self):
- '''Popup a box with about message.'''
- """<b>Platform Details</b> v %s
- <p>Copyright © 2010 Joe Bloggs.
- All rights reserved in accordance with
- GPL v2 or later - NO WARRANTIES!
- <p>This application can be used for
- displaying platform details.
- <p>Python %s - PySide version %s - Qt version %s on %s""" % (__version__,
- platform.system()))
- if __name__ == '__main__':
- frame = MainWindow()
- frame.show()
- app.exec_()
The main program is right at the end. It mostly follows a common pattern. We call the application app and pass to it any CLI arguments in sys.argv. A chosen name for the window frame is frame, but it could be anything at all. frame.show() tells the system to show the frame as soon as the application cycle starts running and finally, app.exec_() starts the application cycle, which enables user interaction by clicking on buttons and the like.
A note about the listing of contents of the text in the about dialog popup box: the character copy; has been re-interpreted to what it represents in HTML, namely little c with a small circle around it. Actually, in the program it needs to be written just as shown in the previous sentence.
The about.py can be run the same way as any other Python program. Enjoy!
Return to PySideSimplicissimus

