first, design three interfaces
Main.ui,do.ui,wait.ui
Picture resources Use the QRC file to control loading:
Content of IMG.QRC:
<! DOCTYPE RCC><RCC version= "1.0" >
<qresource>
<file>bg.jpg</file>
<file>do.jpg</file>
<file>wait.jpg</file>
</qresource>
</RCC>
The display style uses the style sheet QSS to control:
two. Convert the resource control file QRC into a Python file to control resource onboarding
The Convert command is
C:\Python27\Lib\site-packages\PyQt4\pyrcc4.exe-o E:\choice\srcXS\img.py E:\CHOICE\SRCXS\IMG.QRC The first parameter is the converter position,-O is a Common parameters, the third parameter is the generated py file, the fourth parameter is the QRC file location
Third, design python file run.py to use the interface__init__.py This empty file can designate 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) If __name__ = = ' __main__ ': app = Qtgui.qapplication (SYS.ARGV) a=choice ( ) sys.exit ( APP.EXEC_ ())
Folder organization is:
Four, Operation effect
<PY><OOP>PYQT and Qtdesigner mixed use (i) Bernoulli test