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 single-line text Box in PyQt5

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article shares with you the content of a sample analysis of a single-line text box 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.

QLineEdit is a single-line control that allows you to enter and edit plain text. Undo, redo, copy, cut, and paste in the system can all be used for this control.

#! / usr/bin/python3#-*-coding: utf-8-*-import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QLabelclass Example (QWidget): def _ init__ (self): super (). _ init__ () self.initUI () def initUI (self): self.lb1 = QLabel (self) qle = QLineEdit (self) qle.move (60,100) self.lb1.move (60) 40) qle.textChanged [str] .connect (self.onChanged) self.setGeometry (300,300,280,170) self.setWindowTitle ('single line text') self.show () def onChanged (self, text): self.lb1.setText (text) self.lb1.adjustSize () if _ name__ = ='_ main__': app = QApplication (sys.argv) ex = Example () sys.exit (app.exec_ ())

This example shows a single-line text control and a label control. When we edit typed text in a single-line text control, it is immediately displayed in the label control.

Qle = QLineEdit (self)

Create a QLineEdit control object

Qle.textChanged [str] .connect (self.onChanged)

If the text of the single-line text control changes, we call the onChanged () method.

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

In the onChanged () method, we set the contents of the single-line text control to be displayed in the label control. The adjustSize () method resizes the label to the length of the text.

After the program is executed

Thank you for reading! This is the end of the article on "sample analysis of single-line text 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 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