In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to decouple the Python code from the UI file in Python GUI. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
In the actual development, we usually divide the code into interface code and logic code, and the interface is separated from logic. We will demonstrate decoupling logic code in GUI created by Qt designers.
Use Qt designers to create a GUI
First, we create a main window:
Then, add a Table Widgets table control to the main window:
Add two horizontal buttons to the main window:
Then lay out the widgets in the window vertically:
With the basic structure set up, we add rows and columns to the table widget:
After adding rows and columns, we can right-click in the table control and select Edit item to edit the rows and columns:
This completes the layout of the window interface.
Convert UI files to Python files
Instead of using the Qt designer to do any logical work, we just created a basic window layout and now use pyuic5 to convert it to an Python file.
The converted Python file is working properly:
Third, decouple Python logic code
Next, the main window of UI is logically edited by the Python module.
Let's create a new Python file, introduce this GUI window, and run the same result as running the main file directly.
Next, we add default values to the window table in the newly created decouple_window.py file:
In this way, we have set three default data in the table, and now the settings are written directly in the main loop. We can create a new method and place the code for setting the data in it:
In addition to setting the data, we can also add a signal slot to the button so that when the button is clicked, the text of the button changes:
Because of the logic function, our signal slot can bind and call a variety of parts, let's click the button, the button and the text in the table to change.
On how to decouple the Python code from the UI file in Python GUI to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.