I’d like a MessageBox to display when I click a button on my simple PyQT application. How can I declare two textboxes and have a MessageBox display with the text from both textboxes?
Here’s my code far:
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_())
Since such simple code is a common request, I decided to hack something basic together, here you go:
Write something into the line edits (text boxes), click the button. Profit! 🙂
Note: it can be done with less code, but this is a good PyQt coding practice – create a widget to serve as a central widget of a window, populate it with a layout, etc.