Created
May 15, 2015 09:09
-
-
Save Jiezhi/e30d815ba870b6de81a0 to your computer and use it in GitHub Desktop.
pyqt5-beginner-tutorial-part-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://www.thehackeruniversity.com/2014/01/23/pyqt5-beginner-tutorial/ | |
from PyQt5.QtWidgets import * | |
class Form(QWidget): | |
def __init__(self, parent=None): | |
super(Form, self).__init__(parent) | |
nameLabel = QLabel("Name:") | |
self.nameLine = QLineEdit() | |
self.submitButton = QPushButton("Submit") | |
buttonLayout1 = QVBoxLayout() | |
buttonLayout1.addWidget(nameLabel) | |
buttonLayout1.addWidget(self.nameLine) | |
buttonLayout1.addWidget(self.submitButton) | |
self.submitButton.clicked.connect(self.submitContact) | |
mainLayout = QGridLayout() | |
mainLayout.addLayout(buttonLayout1, 0, 1) | |
self.setLayout(mainLayout) | |
self.setWindowTitle("Hello QT") | |
def submitContact(self): | |
name = self.nameLine.text() | |
if name == "": | |
QMessageBox.information(self, "Empty Field", "Please enter a name and address.") | |
return | |
else: | |
QMessageBox.information(self, "Success!", "Hello %s!" % name) | |
if __name__ == '__main__': | |
import sys | |
app = QApplication(sys.argv) | |
screen = Form() | |
screen.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment