I recently downloaded PyQt, which allows me to make GUI’s for my python scripts. I found this website to explain the ins and outs of PyQt. It had one page with some examples and slides dedicated to designing a GUI and implementing it in your python code. It however didn’t fully explain the details. After some fiddling around this is what I found if you want to make python code from your GUI design:
In the examples folder of PyQt (<Your Python Folder>\Lib\site-packages\PyQt4\examples) there are numerous python script examples. In the pyuic folder compile-on-the-fly.pyw can be found which shows how to include a .UI file without having to compile using pyuic4.
This little python code example shows how to use a UI on the fly:
import sys,os from PyQt4 import QtCore, QtGui, uic form_class, base_class = uic.loadUiType('application.ui') class MainWindow(QtGui.QMainWindow): MESSAGE = "Hello!" def __init__(self, parent = None): QtGui.QWidget.__init__(self, parent) self.ui = form_class() self.ui.setupUi(self) self.ui.pushButton.clicked.connect(self.informationMessage) def informationMessage(self): reply = QtGui.QMessageBox.information(self, "QMessageBox.information()", MainWindow.MESSAGE) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = MainWindow() myapp.show() sys.exit(app.exec_())
The needed application.ui is just a simple GUI with a button named ‘pushButton’, made in Qt Designer.