博客
关于我
PyQt5实现点击按钮获取文本框的值
阅读量:329 次
发布时间:2019-03-04

本文共 1433 字,大约阅读时间需要 4 分钟。

目录

为了便于后期更新,所有目录已汇总到一个链接,具体请移步到

正文

本文主要介绍PyQt5中文本框的使用。其中,使用textbox.setText(string) 方法设置文本框内容,使用textbox.text() 获取文本框里面的内容。

import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QAction, QMessageBoxfrom PyQt5.QtGui import QIconfrom PyQt5.QtCore import pyqtSlotfrom PyQt5.Qt import QLineEditclass App(QWidget):        def __init__(self):        super().__init__()        self.title = 'PyQt5 textbox'        self.left = 10        self.top = 10        self.width = 320        self.height = 200        self.initUI()        def initUI(self):        self.setWindowTitle(self.title)        self.setGeometry(self.left, self.top, self.width, self.height)                # create textbox        self.textbox = QLineEdit(self)        self.textbox.move(20, 20)        self.textbox.resize(280, 40)                # Create a button in the window        self.button = QPushButton('show text', self)        self.button.move(20, 80)                # connect button to function on_click        self.button.clicked.connect(self.on_click)        self.show()             @pyqtSlot()    def on_click(self):        textboxValue = self.textbox.text()        QMessageBox.question(self, "Message", 'You typed:' + textboxValue,                              QMessageBox.Ok, QMessageBox.Ok)        """打印完毕之后清空文本框"""        self.textbox.setText('')if __name__ == '__main__':    app = QApplication(sys.argv)    ex = App()    app.exit(app.exec_())

转载地址:http://whgq.baihongyu.com/

你可能感兴趣的文章
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>
MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
查看>>
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>
MySQL - 解读MySQL事务与锁机制
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>