这是我第一次尝试在 python 中使用 gui,我需要帮助输出我在运行 gui 时设置的信息。在我点击提交按钮后,它应该打印出类似于下面的所有内容。如果需要任何进一步的信息,我会编辑它。例如性别:男性姓名:姓名年龄:#等
import sys
from PyQt4 import QtGui, QtCore
class Gui(QtGui.QMainWindow):
def __init__(self):
super(Gui, self).__init__()
self.initUI()
def initUI(self):
#Frame
self.setGeometry(100, 100, 400, 600)
self.setWindowTitle('Python Printer')
#Button
self.btn1 = QtGui.QPushButton("Submit", self)
self.btn1.setGeometry(QtCore.QRect(90, 560, 75, 30))
self.btn1.clicked.connect(self.buttonClicked)
self.btn2 = QtGui.QPushButton("Cancel", self)
self.btn2.setGeometry(QtCore.QRect(170, 560, 75, 30))
self.btn2.clicked.connect(self.buttonClicked)
#Text Field
self.texta = QtGui.QPlainTextEdit("Name",self)
self.texta.setGeometry(QtCore.QRect(75,155,150,25))
self.textb = QtGui.QPlainTextEdit("Surname",self)
self.textb.setGeometry(QtCore.QRect(75,125,150,25))
self.textc = QtGui.QPlainTextEdit("#",self)
self.textc.setGeometry(QtCore.QRect(75,215,30,25))
self.textd = QtGui.QPlainTextEdit("##/##/####",self)
self.textd.setGeometry(QtCore.QRect(75,275,120,25))
self.texte = QtGui.QPlainTextEdit("",self)
self.texte.setGeometry(QtCore.QRect(75,345,150,25))
#Label
self.labl1 = QtGui.QLabel("Gender",self)
self.labl1.setGeometry(QtCore.QRect(75,30,150,25))
self.labl2 = QtGui.QLabel("Legal Name",self)
self.labl2.setGeometry(QtCore.QRect(75,100,150,25))
self.labl3 = QtGui.QLabel("Age",self)
self.labl3.setGeometry(QtCore.QRect(75,190,150,25))
self.labl4 = QtGui.QLabel("Birthdate (MM/DD/YYYY)",self)
self.labl4.setGeometry(QtCore.QRect(75,250,150,25))
self.labl5 = QtGui.QLabel("Email",self)
self.labl5.setGeometry(QtCore.QRect(75,320,150,25))
#Combo Box
self.combox = QtGui.QComboBox(self)
self.combox.addItem("Select")
self.combox.addItem("Male")
self.combox.addItem("Female")
self.combox.addItem("Other")
self.combox.setGeometry(QtCore.QRect(75,50,150,25))
self.show()
def buttonClicked(self):
print("Profile")
#output
def main():
app = QtGui.QApplication(sys.argv)
ex = Gui()
sys.exit(app.exec_())
if __name__ == '__main__':
main()