博客
关于我
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/

你可能感兴趣的文章
Mysql不同官方版本对比
查看>>
MySQL与Informix数据库中的同义表创建:深入解析与比较
查看>>
mysql与mem_细说 MySQL 之 MEM_ROOT
查看>>
MySQL与Oracle的数据迁移注意事项,另附转换工具链接
查看>>
mysql丢失更新问题
查看>>
MySQL两千万数据优化&迁移
查看>>
MySql中 delimiter 详解
查看>>
MYSQL中 find_in_set() 函数用法详解
查看>>
MySQL中auto_increment有什么作用?(IT枫斗者)
查看>>
MySQL中B+Tree索引原理
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中datetime与timestamp类型有什么区别
查看>>
MySQL中DQL语言的执行顺序
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
MySQL中interactive_timeout和wait_timeout的区别
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>