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
- Turn on pycharm settings
- Find Tools-External Tools
- 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