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的更多相关文章

  1. PyQt4入门学习笔记(五)

    PyQt4里的对话框 对话框是大多数GUI应用中不可分割的一部分.一个对话框是两者或多者的会话.在GUI内,对话框是应用向人说话的方式.一个对话框可以用来输入数据,修改数据,改变应用设置等等. QtG ...

  2. PyQt4入门

    PyQt4入门教程(6)_对话框 文中译者的话将用方括号[]标出.对话框(Dialogs)是现代GUI程序中不可缺少的一部分.对话本来指的是两个或者更多人之间的交流,而在计算机应用中,对话是一个可以让 ...

  3. Qt: 内建对话框(各种对话框都有了,且用到了qobject_cast解析sender的技术)

    #include "BuiltinDialog.h" #include <QtGui/QTextEdit> #include <QtGui/QPushButton ...

  4. pyqt小例子 音乐盒

    源代码1: # -*- coding: utf-8 -*- import sys,time,os import ctypes from PyQt4 import QtCore, QtGui,Qt fr ...

  5. pyqt tabliwdget表头属性修改

    # -*- coding: utf-8 -*-__author__ = 'Administrator'import sysfrom PyQt4 import QtGui class MyWindow( ...

  6. Pyqt4的对话框 -- 预定义对话框

    QinputDialog提供了一种获取用户单值数据的简介形式. 它接受的数据有字符串.数字.列表中的一项数据 # QInputDialog 输入对话框 # 本示例包含一个按钮和一个行编辑部件.单击按钮 ...

  7. QDialog:输入对话框、颜色对话框、字体对话框、文件对话框

    # _*_ coding:utf-8 _*_ import sys from PyQt4 import QtCore,QtGui class Example(QtGui.QWidget): def _ ...

  8. PyQt4预定义对话框

    PyQt4中的对话框 对话窗口和对话框是现代GUI应用程序必不可少的一部分.生活中“对话”被定义为发生在两人或更多人之间的会话.而在计算机世界,“对话”则时人与应用程序之间的“会话”.人及对话的形式有 ...

  9. ZetCode PyQt4 tutorial Dialogs

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

随机推荐

  1. android bitmap recycle

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 不需要位图的时候,就可以手动调用recycle. 2.3之前 位图对象 存在 java的 ...

  2. 【欧拉定理】BZOJ3884-上帝与集合的正确用法

    [题目大意] 求2^(2^(2^(2^(2^...)))) mod p. [思路] 蒟蒻在知道用欧拉做的前提下,对这题目瞪了好久没有明白,看了正解扑通一声跪下来orz直接搬运popoqqq大爷的吧反正 ...

  3. bzoj 1789: [Ahoi2008]Necklace Y型项链 贪心

    1789: [Ahoi2008]Necklace Y型项链 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/Jud ...

  4. PAT甲级1089. Insert or Merge

    PAT甲级1089. Insert or Merge 题意: 根据维基百科: 插入排序迭代,消耗一个输入元素每次重复,并增加排序的输出列表.每次迭代,插入排序从输入数据中删除一个元素,在排序列表中找到 ...

  5. JAVA 垃圾收集监控

    我们可以使用Java命令行和UI工具来监控应用程序的垃圾收集活动.下面的例子中,我使用Java SE Downloads 中一个演示程序. 如果你想使用同样的程序,前往 Java SE Downloa ...

  6. Vue学习记录-状态管理

    要解决的问题 平时的系统开发中,基本都会碰到这个权限问题,需要根据用户的登录状态进行处理.最常见的情况就是“先登录,后使用”.除去打包成APP,无法看到连接外,如果地址栏里直接输入地址就能绕过登录的话 ...

  7. Android 动画——属性动画Property Animation

    Android在3.0之前只提供了两种动画:View Animation .Drawable Animation .也就是我们在<Android 动画——Frame Animation与Twee ...

  8. Android的Master/Detail风格界面中实现自定义ListView的单选

    原文在这里:http://duduli.iteye.com/blog/1453576 可以实现多选,那么如何实现单选呢,这里我写了一个非常简单的方法: public void onListItemCl ...

  9. booksleeve 使用

    By offering pipelined, asynchronous, multiplexed and thread-safe access to redis, BookSleeve enables ...

  10. 在Ubuntu 13.04下的安装eclipse

    来源:http://www.cnblogs.com/lanxuezaipiao/p/3325628.html 一.eclipse安装过程 首先确保在安装eclipse之前已经安装好Java虚拟机 1. ...