<PY><OOP>PYQT and Qtdesigner mixed use (i) Bernoulli test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.