<PY> <OOP> hybrid use of PyQt and QtDesigner (1) bonuli test, pyqtqtdesigner
I. design three interfaces
Main. ui, do. ui, wait. ui
Image resources use the qrc file to Control Loading:
Img. qrc content:
<! Doctype rcc> <RCC version = "1.0">
<Qresource>
<File> bg.jpg </file>
<File> do.jpg </file>
<File> wait.jpg </file>
</Qresource>
</RCC>
The style table qss is used to control the display style:
2. Convert the resource control file qrc into a python file to control resource loading.
The conversion command is
C: \ Python27 \ Lib \ site-packages \ PyQt4 \ pyrcc4.exe-o E: \ choice \ srcXS \ img. py E: \ choice \ srcXS \ img. the first parameter of qrc is the converter location,-o is a common parameter, the third parameter is the generated py file, and the fourth parameter is the qrc file location.
3. Design the python file run. py to use the interface _ init _. py, which can specify a folder as a python package.
# Run. py
from PyQt4 import QtGui,uicimport sys,srcXS.imgfrom random import randintdef show_only(windows, n): for i, window in enumerate(windows): if i != int(n): window.hide() else: window.show()class Choice(QtGui.QFrame): def __init__(self): super(QtGui.QFrame, self).__init__() self.windows=[uic.loadUi('main.ui'),uic.loadUi('wait.ui'),uic.loadUi('do.ui')] show_only(self.windows,0) self.windows[0].chooseButton.clicked.connect(lambda: self.btn_tapped()) def btn_tapped(self): show_only(self.windows,randint(1,2))if __name__ == '__main__': app = QtGui.QApplication(sys.argv) a=Choice() sys.exit(app.exec_())
The folder is organized as follows:
Iv. Running Effect