Mac Install PyQt5

Source: Internet
Author: User
Tags emit install brew qt designer

1. Install Brew

" $ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install) "

2. Install Python3

Install
Brew Info Python3
Python3-v

3. Install SIP & PYQT5

InstallInstall pyqt

simple.py

ImportSYS fromPyqt5.qtwidgetsImportQmainwindow, Qtextedit, Qapplication, Qapp, Qaction fromPyqt5.qtguiImportQiconclassSimple (Qmainwindow):def __init__(self): Super ().__init__() Self.initui ()defInitui (self): Self.setwindowtitle ('Hello') Self.setobjectname ("Hellowin") Self.resize (500, 300)if __name__=='__main__': App=qapplication (SYS.ARGV) ex=Simple () ex.show () Sys.exit (App.exec_ ())
View Code

simple2.py

#-*-coding:utf-8-*-ImportSYS fromPyqt5.qtwidgetsImport* fromPyqt5.qtcoreImport*classFirstwindow (qwidget): Signal=pyqtsignal (str)def __init__(Self, parent=None):#Super This usage is called the constructor of the parent class        #Parent=none indicates that there is no parent widget by default, and if you specify a Father widget, call theSuper (Firstwindow, self).__init__(parent) self.resize (100, 100) self.btn=Qtoolbutton (self) self.btn.setText ("Click") Self.signal.connect (self.sincall)defSincall (self, text):Print("sin Emit:", text) self.btn.setText (text)defcloseevent (Self, event): Result=qmessagebox.question (self,"Confirm Exit ...",                      "Is you sure want to exit?", Qmessagebox.yes|qmessagebox.no) Event.ignore ()ifresult = =QMessageBox.Yes:event.accept ()classSecondwindow (qwidget):def __init__(Self, parent=None): Super (Secondwindow, self).__init__(parent) self.resize (200, 200) Self.setstylesheet ("Background:black")            defHandle_click (self):if  notself.isvisible (): Self.show ()defHandle_close (self): Self.close ()if __name__=="__main__": App=qapplication (SYS.ARGV) ex=Firstwindow () s=Secondwindow () ex.btn.clicked.connect (S.handle_click)#Ex.btn.clicked.connect (ex.hide)Ex.signal.emit ("Signal Text") Ex.show () Sys.exit (App.exec_ ())
View Code

4. Install Qt (optional, easy to do interface, similar to WinForm do interface: interface visualization tools, can be easily designed UI, WYSIWYG)
A. Install Xcode
B. Download Qt https://www.qt.io/download/

5. Install pycharm (optional, IDE, easy to develop: can integrate QT; Qt ui file goto py; run Python directly)
A. Configure the QT DESIGNER:QT Interface visualization tool, can easily design the UI, WYSIWYG

    1. Turn on pycharm settings
    2. Find Tools-External Tools
    3. Click +--Create Tool


      B. Configure Pyuic: This tool can convert QT Designer UI files to py files

      Python-m PyQt5.uic.pyuic $FileName $-O $FileNameWithoutExtension $.py

      C. Select External Tools in the right-click menu

6.install Pyinstaller (optional, Python to executable file: exe, pkg))

Install-F-W {pyfile}.py

Mac Install PyQt5

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.