QtGui.QInputDialog
The QtGui.QInputDialog provides a simple convenience dialog to get a single value from the user. The input value can be a string, a number or an item from a list.
#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we receive data from
a QtGui.QInputDialog dialog. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.btn = QtGui.QPushButton('Dialog', self)
self.btn.move(20, 20)
self.btn.clicked.connect(self.showDialog) self.le = QtGui.QLineEdit(self)
self.le.move(130, 22) self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Input dialog')
self.show() def showDialog(self): text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog',
'Enter your name:') if ok:
self.le.setText(str(text)) def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
The example has a button and a line edit widget. The button shows the input dialog for getting text values. The entered text will be displayed in the line edit widget.
text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog',
'Enter your name:')
This line displays the input dialog. The first string is a dialog title, the second one is a message within the dialog. The dialog returns the entered text and a boolean value. If we click the Ok button, the boolean value is true.
if ok:
self.le.setText(str(text))
The text that we have received from the dialog is set to the line edit widget.
Figure: Input Dialog
QtGui.QInputDialog的更多相关文章
- PyQt4入门学习笔记(五)
PyQt4里的对话框 对话框是大多数GUI应用中不可分割的一部分.一个对话框是两者或多者的会话.在GUI内,对话框是应用向人说话的方式.一个对话框可以用来输入数据,修改数据,改变应用设置等等. QtG ...
- PyQt4入门
PyQt4入门教程(6)_对话框 文中译者的话将用方括号[]标出.对话框(Dialogs)是现代GUI程序中不可缺少的一部分.对话本来指的是两个或者更多人之间的交流,而在计算机应用中,对话是一个可以让 ...
- Qt: 内建对话框(各种对话框都有了,且用到了qobject_cast解析sender的技术)
#include "BuiltinDialog.h" #include <QtGui/QTextEdit> #include <QtGui/QPushButton ...
- pyqt小例子 音乐盒
源代码1: # -*- coding: utf-8 -*- import sys,time,os import ctypes from PyQt4 import QtCore, QtGui,Qt fr ...
- pyqt tabliwdget表头属性修改
# -*- coding: utf-8 -*-__author__ = 'Administrator'import sysfrom PyQt4 import QtGui class MyWindow( ...
- Pyqt4的对话框 -- 预定义对话框
QinputDialog提供了一种获取用户单值数据的简介形式. 它接受的数据有字符串.数字.列表中的一项数据 # QInputDialog 输入对话框 # 本示例包含一个按钮和一个行编辑部件.单击按钮 ...
- QDialog:输入对话框、颜色对话框、字体对话框、文件对话框
# _*_ coding:utf-8 _*_ import sys from PyQt4 import QtCore,QtGui class Example(QtGui.QWidget): def _ ...
- PyQt4预定义对话框
PyQt4中的对话框 对话窗口和对话框是现代GUI应用程序必不可少的一部分.生活中“对话”被定义为发生在两人或更多人之间的会话.而在计算机世界,“对话”则时人与应用程序之间的“会话”.人及对话的形式有 ...
- ZetCode PyQt4 tutorial Dialogs
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
随机推荐
- 51nod1821 最优集合 贪心
首先考虑一个集合的最大优美值怎么求出 考虑新增一个数,假设我们现在的优美值已经达到了$V$,那么只需要一个$[1, V + 1]$的数就可以使$V$达到更大 为了保证能添加尽可能多的数进来,我们这么构 ...
- Map按照数值进行排序
public static Map<String, Integer> sortMapByValue(Map<String, Integer> oriMap) { if (ori ...
- ROS知识(4)----初级教程之常见问题汇总
一.开机启动ROS的工作空间的路径设置失败 现象:在教程:http://wiki.ros.org/cn/ROS/Tutorials/CreatingPackage中的第5.1小节,运行以下命令失败: ...
- 也谈时间管理和GTD
也谈时间管理和GTD 时间管理 随着事情越来约多发现时间越来越不够用了,但是其实每天时间都是恒定的,并不增也不减,所以感觉时间不够用了总归只是个人主观感觉. 对我个人帮助比较大的是三本书<番茄时 ...
- CentOS的rpm常用命令(转)
一.RPM 安装操作 命令: rpm -i 需要安装的包文件名 举例如下: rpm -i example.rpm 安装 example.rpm 包: rpm -iv example.rpm 安装 ex ...
- Regulator IC forms convenient overvoltage detector
Figure 1 shows a simple, stand-alone overvoltage detector. The intent of the circuit is to monitor a ...
- Si4455 低电流 Sub-GHz收发器
Silicon Labs 的 Si4455 是易于使用的低电流 Sub-GHz EZRadio® 收发器.覆盖所有主要波段,结合了即插即用的简单性和需要处理各种不同应用的灵活性.紧凑的 3 mm x ...
- sqlserver获取所有表和表字段
SELECT [number]=a.colorder, [column] =a.name, [datatype]=b.name, [length]=COLUMNPROPERTY(a.id,a.name ...
- node升级后,项目中的node-sass报错的问题
之前可能因为电脑不知道哪抽风了,在npm build的时候进入就卡在入口的地方,启动express的时候也会,所以就重装了一下node 重装node 其实也不是重装,就是使用 where node 查 ...
- java 日期工具类
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; imp ...