& Lt; PY & gt; & lt; OOP & gt; hybrid use of PyQt and QtDesigner (1) bonuli test, pyqtqtqtdesigner

Source: Internet
Author: User

<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













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.