PyQt安装程序附带一个名为Qt Designer的GUI创建器工具使用其简单的拖放界面,可以快速创建GUI界面,而无需编写代码。但是,不是像Visual Studio这样的IDE。因此,Qt Designer没有调试和创建应用程序的功能。

使用Qt Designer创建GUI界面首先为应用程序选择顶级窗口。



Qt Designer2

The designed form is saved as demo.ui. This ui file contains XML representation of widgets and their properties in the design. This design is translated into Python equivalent by using pyuic4 command line utility. This utility is a wrapper for uic module. The usage of pyuic4 is as follows −

pyuic4 –x demo.ui –o demo.py

In the above command, -x switch adds a small amount of additional code to the generated XML so that it becomes a self-executable standalone application.

if __name__ == "__main__":
   import sys
   app = QtGui.QApplication(sys.argv)
   Dialog = QtGui.QDialog()
   ui = Ui_Dialog()

The resultant python script is executed to show the following dialog box −


The user can input data in input fields but clicking on Add button will not generate any action as it is not associated with any function. Reacting to user-generated response is called as event handling.