综合实例-文本框类部件

复制代码
 1 import sys
 2 from PyQt5.QtWidgets import QApplication, QLineEdit, QWidget, QFormLayout
 3 from PyQt5.QtGui import QIntValidator, QDoubleValidator, QFont
 4 from PyQt5.QtCore import Qt
 5 
 6 
 7 class lineEditDemo(QWidget):
 8 
 9     def __init__(self):
10         super(lineEditDemo, self).__init__()
11 
12         e1 = QLineEdit()
13         e1.setValidator(QIntValidator())
14         e1.setMaxLength(4)
15         e1.setAlignment(Qt.AlignRight)
16         e1.setFont(QFont("Arial", 20))
17         e2 = QLineEdit()
18         e2.setValidator(QDoubleValidator(0.99, 99.99, 2))
19         flo = QFormLayout()
20         flo.addRow("integer validator", e1)
21         flo.addRow("Double validateor", e2)
22         e3 = QLineEdit()
23         e3.setInputMask("+99_9999_999999")
24         flo.addRow("Input Mask", e3)
25         e4 = QLineEdit()
26         e4.textChanged.connect(self.textchanged)
27         flo.addRow("Text changed", e4)
28         e5 = QLineEdit()
29         e5.setEchoMode(QLineEdit.Password)
30         flo.addRow("Password", e5)
31         e6 = QLineEdit("Hello PyQt5")
32         e6.setReadOnly(True)
33         flo.addRow("Read Only", e6)
34         e5.editingFinished.connect(self.enterPress)
35         self.setLayout(flo)
36         self.setWindowTitle("QLineEdit例子")
37 
38     def textchanged(self, text):
39         print("输入的内容为: "+ text)
40 
41     def enterPress(self):
42         print("已输入值")
43 
44 if __name__ == '__main__':
45     app = QApplication(sys.argv)
46     win = lineEditDemo()
47     win.show()
48     sys.exit(app.exec_())
复制代码

效果图:

 

posted @   胸怀丶若谷  阅读(132)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 百万级群聊的设计实践
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
点击右上角即可分享
微信分享提示