Using PYCHARM+PYQT5 to tune the interface program

Source: Internet
Author: User

First, the use of Qtdesigner production interface

1) Open the interface design tool Qtdesigner,



2) Create a new form and select Main Window:



3) Add the following controls to the window, Calendar, 3 pushbutton, CheckBox, text Browser, Text Edit, respectively:



4) Drag the control and save it to the Pycharm project folder to generate the corresponding. ui file:




5) Right-click the. ui file to convert using the Pyuic tool. The UI code is a. PY code:

6) successfully generated. py file:

7) Delete the following three lines:

Mainwindow.setcentralwidget (Self.centralwidget),
Mainwindow.setmenubar (Self.menubar),
Mainwindow.setstatusbar (Self.statusbar)



8) Add the following code at the bottom:

if __name__== "__main__":      import  sys      app= qtwidgets.qapplication (sys.argv)      widget=qtwidgets.qwidget ()      ui=ui_ MainWindow ()      ui.setupui (widget)      widget.show ()      sys.exit (App.exec_ ())  



9) Right-click Run to see the graphical interface:

Graphical interface:



Second, in the Pycharm with their own code to adjust the graphical interface:

1.) Create a new. py file in the project, my name is blogtest.py:




2) Separately in the file, add the following:

Write a class, inherit the interface UI class, add the initialization method, the code entrance uses the Show method to display the interface, the code is as follows:

ImportSYS fromBlogImportUi_mainwindow fromPyQt5ImportqtwidgetsclassMywindow (Qtwidgets.qwidget, Ui_mainwindow):def __init__(self): Super (Mywindow, self).__init__() self.setupui (self)if __name__=="__main__": App=qtwidgets.qapplication (SYS.ARGV) myshow=Mywindow () myshow.show () Sys.exit (App.exec_ ())

3) Right-click to run, the interface appears:

4)

Adding control events in Qtdisigner

1) Open Qtdesigner load the last build UI file:

2) Add control event:

QT in the control event triggers are unified called slots and Signals, I understand as the trigger source and target source, the event is added by using the edit slot/signal function in Qtdesigner, click the trigger source, drag the signal line to the target source, for example, I used pushbutton as the trigger source, Calendar as the target source, after the drag is finished, the event will appear in the edit bar, the left of the event to trigger the source, the right side of the target source of the event, select each, the steps such as:

3) In the same vein, two events were added with two buttons, and Qtdesigner displays the events for each trigger source and target Source:



4) Save the UI file, generate the. py file in the Pycharm, you can see the added events in the code, QT uses the Connect method connected slots and signals, remember to delete the three lines of code that affect the compilation:

Second, the operation effect:

1). py Running the Fetch window

2) After running, click the two pushbutton respectively, you can see the calendar control of the hidden and display features:

Hide:



Show:

Using PYCHARM+PYQT5 to tune the interface program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.