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

Example Analysis of combo Box in PyQt5

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about the sample analysis of combo boxes in PyQt5. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

QComboBox is a control that allows the user to select an item from a list of options.

#! / usr/bin/python3#-*-coding: utf-8-*-"" PyQt5 tutorial this example shows how to use QComboBox parts. Last editor: import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBoxclass Example (QWidget): def _ _ init__ (self): super (). _ init__ () self.initUI () def initUI (self): self.lb1 = QLabel ('Matrix' Self) combo = QComboBox (self) combo.addItem ('Matrix') combo.addItem ('Lord of the Rings') combo.addItem ('Avengers') combo.addItem ('Avatar') combo.addItem ('X-Men') combo.move (50,50) self.lb1.move (50150) combo.activated.connect (self.onActivated) self.setGeometry (300,300,300) Self.setWindowTitle ('combo box') self.show () def onActivated (self, text): self.lb1.setText (text) self.lb1.adjustSize () if _ _ name__ ='_ main__': app = QApplication (sys.argv) ex = Example () sys.exit (app.exec_ ())

There are five options in the combo box. The label control is used to display the options selected from the combo box.

Combo = QComboBox (self) combo.addItem ('Matrix') combo.addItem ('Lord of the Rings') combo.addItem ('Avengers') combo.addItem ('Avatar') combo.addItem ('X-Men')

We create a QComboBox part with five options.

Combo.activate [str] .connect (self.onActivated)

When the project is selected in QComboBox, we call the onActivated () method.

Def onActivated (self, text): self.lb1.setText (text) self.lb1.adjustSize ()

In the onActivated () method, we set the label control to display the text of the selected item. AdjustSize () resizes the label.

After the program is executed

Thank you for reading! This is the end of this article on "sample analysis of combo boxes in PyQt5". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out 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.

Share To

Development

Wechat

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

12
Report