我想在单击简单PyQT应用程序上的按钮时显示一个消息框。如何声明两个文本框并让一个消息框显示两个文本框中的文本?
这是我的密码:
import sys
from PyQt4 import QtGui, QtCore
class myWindow(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
#The setGeometry method is used to position the control.
#Order: X, Y position - Width, Height of control.
self.setGeometry(300, 300, 500, 350)
self.setWindowTitle("Sergio's QT Application.")
self.setWindowIcon(QtGui.QIcon('menuScreenFolderShadow.png'))
self.setToolTip('<i>Welcome</i> to the <b>first</b> app ever!')
QtGui.QToolTip.setFont(QtGui.QFont('Helvetica', 12))
txtFirstName = QtGui.?
txtLastName = QtGui.?
btnQuit = QtGui.QPushButton('Exit Application', self)
btnQuit.setGeometry(340, 300, 150, 35)
self.connect(btnQuit, QtCore.SIGNAL('clicked()'),
QtGui.qApp, QtCore.SLOT('quit()'))
app = QtGui.QApplication(sys.argv)
mainForm = myWindow()
mainForm.show()
sys.exit(app.exec_())
因为这样简单的代码是一个常见的请求,所以我决定将一些基本的代码一起破解,下面是:
在行编辑(文本框)中写入内容,单击按钮。利润!:-)
注意:这可以用更少的代码完成,但这是一个很好的PyQt编码实践-创建一个小部件作为窗口的中心小部件,用布局填充它,等等
PyQt在安装时附带了一些示例。这些示例包含许多非常有用的代码,您可以从中学习,也可以获取整个代码块并使用它们。
例如,查看“地址簿”示例,该示例将消息框与其他内容一起弹出(在其源中搜索“messagebox”)。
资料来源:
相关问题 更多 >
编程相关推荐