Last active
August 29, 2015 13:57
-
-
Save remram44/9643396 to your computer and use it in GitHub Desktop.
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
| # -*- encoding: utf-8 -*- | |
| import sys | |
| # Complicated stuff | |
| import sip | |
| api2_classes = [ | |
| 'QData', 'QDateTime', 'QString', 'QTextStream', | |
| 'QTime', 'QUrl', 'QVariant'] | |
| for cl in api2_classes: | |
| try: | |
| sip.setapi(cl, 2) | |
| except ValueError: | |
| pass | |
| from PyQt4 import QtCore, QtGui | |
| if __name__ == '__main__': | |
| # Crée une application | |
| app = QtGui.QApplication(sys.argv) | |
| # Une fenêtre, avec un layout vertical | |
| window = QtGui.QWidget() | |
| window.setLayout(QtGui.QVBoxLayout()) | |
| # Un layout horizontal pour le label et le lineedit | |
| prompt = QtGui.QHBoxLayout() | |
| # Label | |
| prompt.addWidget(QtGui.QLabel(u"Nom :")) | |
| # Lineedit | |
| name = QtGui.QLineEdit() | |
| prompt.addWidget(name) | |
| # Ajoute le layout horizontal dans le layout vertical | |
| window.layout().addLayout(prompt) | |
| # Un bouton | |
| button = QtGui.QPushButton(u"Go !") | |
| # Action quand on clique le bouton | |
| def say_it(): | |
| QtGui.QMessageBox.information(window, u"Greeting", u"Hi, %s" % name.text()) | |
| button.clicked.connect(say_it) | |
| # Ajoute le bouton dans le layout vertical (sous les deux autres widgets) | |
| window.layout().addWidget(button) | |
| # Retaille et affiche la fenêtre | |
| window.show() | |
| window.adjustSize() | |
| # Boum | |
| app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment