Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a complex GUI in Python

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to create a complex GUI in Python, I believe that many inexperienced people are helpless about this, so this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.

Creating a complex GUI

We used Qt Designer to create a slightly more complex GUI. These include:

Two Tabs Widgets

Two Tabs Widgets

A Date Part DateEdit

A calendar widget CalendarWidget

A Tree Widget

A GroupBox

Three radio buttons RadioButton

A font selection box FontComboBox

A Lable label

A progress bar

A dial

An LCD data display LcdNumber

All the steps can be completed by dragging and dropping Qt Designer.

Create Main Tab

Create a new main window and drag the TabWidget widget into the main window:

Create a subtab in Tab 1

Continuing with the TabWidget widget, create a subtab in Tab 1:

Add a tree part to subtab 1

We continue with the TreeWidget widget, creating a tree in subtab 1 we just created, and adding some information:

Add date and calendar parts in subtab 2

Now switching to subtab 2, we use the Date Edit widget and Calendar Widget widget to add a date modification box and a calendar box in subtab 2, in a vertical layout:

Add button group in Tab 2

Tab 1 is built, now switch to Tab 2.

Let's start by creating a group widget using the GroupBox widget, and then add three PushButton widgets to it:

Add scale and LCD parts in tab 2

We add a dial and LCD display to tab 2, placed in a group part:

Add a font selector to tab 2

Next, using the FontComboBox widget and Label widget, add a font selector and text display in Tab 2:

Add a progress bar to tab 2

Finally, we use the ProcessBar widget to add a progress bar to tab 2:

This completes the GUI design.

Next, we create signals/slots to implement the GUI's event response.

Build Signal/Slot Conversion UI File to Python File

We first convert the designed UI file to a Python file, separating the interface code from the logic code according to the previous decoupling idea.

After converting the UI file, create a Python file and introduce the GUI window converted to Python code:

Run it and see if it's normal:

Create a new logical class

To make things easier, we create a new class MainWindow, put the main loop of the program into it, and add the rest of the logic in the form of methods of the class:

Synchronizing calendar selection to date selector

We built a date modifier and a calendar in tab 1, subtab 2.

When we click on a date on the calendar, the date modifier displays the date we choose synchronously.

In the MainWindow() class, we create a new update_date() method to set the value of the date modifier:

Create an update_calendar() method to set the signal/slot for clicking on the calendar and respond to it on the date modifier:

The complete code is as follows:

So we click on a date on the calendar, and the date modifier shows us the date we clicked on.

LCD Display Digital Follows Dial Change

We placed a Dial dial and LCD Number display in the assembly subassembly.

We can set the numbers on the LCD display to follow the dial changes.

Again, create two methods:

A number to set the LCD display and a signal to respond to the dial.

Implementation button control progress bar

We placed 3 radio buttons and a progress bar in Tab 2, and now we let the radio buttons control the progress bar. The first button is the default option, the second button resets the progress bar, and the third button updates according to the number on the LCD.

Set the second button to clear the progress bar and create a new method:

Set the function of the third button and create two new methods:

Update font selection

We also put a font selection widget and a label widget in tab 2. We can set a font selection to display on the label.

This completes a slightly more complex GUI.

After reading the above, do you know how to create a complex GUI in Python? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report