This article describes creating a GUI with Qtdesigner and converting it to an executable python file via PyQt4
1. Qtdesigner A. ui file (Eg:TestUI.ui) is generated when a GUI is created
2. Generate the Py file (testui.py) We need by command Python Pyuic.py-o testui.py testui.ui
3. Create a test.py file and edit the following code:
1 ImportSYS2 fromPyqt4.qtguiImport*3 fromPyqt4.qtcoreImport*4 ImportTestui5 6 classUITest (Qmainwindow,testui.ui_mainwindow):7 def __init__(Self, parent=None):8Super (UITest, self).__init__(parent)9 self.setupui (self)Ten OneApp =qapplication (SYS.ARGV) AW =uitest () - w.show () -APP.EXEC_ ()
4. Python test.py to get the GUI you designed in step 1
NOTE: Pyuic parameter description:
NAME
Pyuic4-compile QT4 user interfaces to Python code
Synopsis
PYUIC4 [OPTION] ... FILE
DESCRIPTION
Pyuic4 takes a QT4 user interface description file and compiles it to
Python code. It can also show a preview of the user interface.
OPTIONS
-H,--help
Show a summary of the options.
--version
Display The version number of PYUIC4 of the version of Qt which
PYQT4 is generated for.
-P,--preview
Show a preview of the UI instead of generating Python code.
-O,--output=file
Write the generated Python code to FILE instead of stdout.
-D,--debug
Show detailed debugging information about the UI generation
Process.
-X,--execute
Generate extra code to test and display the class when executed
As a script.
-I.,--indent=num
Set the indentation width to NUM spaces. A TAB character'll be
Used if NUM is 0 (default:4).
Qtdesigner PyQt4 Python