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, ...
随机推荐
- 「BZOJ 2534」 L - gap字符串
「BZOJ 2534」 L - gap字符串 题目描述 有一种形如 \(uv u\) 形式的字符串,其中 \(u\) 是非空字符串,且 \(v\) 的长度正好为 \(L\), 那么称这个字符串为 \( ...
- [ARC053D]2 つの山札
题意:给定排列$a_{1\cdots n},b_{1\cdots n}$,执行以下操作$2n-2$次来生成一个长度为$2n-2$的序列:选择$a,b$之一(选择的序列长度要$\geq2$),删除它的第 ...
- 1.8(SQL学习笔记)触发器
一.触发器简介 当需要某些操作在某些语句执行之前或之后执行就需要使用触发器. 例如每次插入数据时进行数据校对,每次删除数据后将删除内容备份到新表. 这些操作我们希望它(某些语句)在满足某些条件时自动执 ...
- pat 打印沙漏
本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号:各行符号中心对齐:相邻两 ...
- 11.m进制转十进制
Strlen是字符串有多长就是多长,包括所有的元素和\0这个结束符 题目描述 Description 将m进制数n转化成一个十进制数 m<=16 题目保证转换后的十进制数<=100 输入描 ...
- git -- 简单命令
1.git init 当前目录初始化 2.git status 检查当前文件状态 Changes to be committed” 这行下面的,就说明是已暂存状态 Changed b ...
- [转]ADT中通过DDMS导入文件出错ddms transfer error: Read-only file system,Failed to push selection: Read-only file system
[已解决] 原文 http://www.crifan.com/ddms_import_file_error_transfer_error_read_only_file_system/ 想要通过adt ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树
E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...
- hdu 5204 Rikka with sequence 智商不够系列
Rikka with sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...
- Low-cost ADC using only Digital I/O
http://letsmakerobots.com/node/13843 Reading A Sensor With Higher Accuracy – RC Timing Method RC Tim ...