1. install brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. install python3

brew install python3 
brew info python3
python3 -V

3. install sip & pyqt5

pip3 install sip
pip3 install pyqt5

simple.py

import sys
from PyQt5.QtWidgets import QMainWindow, QTextEdit, QApplication, qApp, QAction
from PyQt5.QtGui import QIcon class simple(QMainWindow): def __init__(self):
super().__init__()
self.initUI() def initUI(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_())

simple2.py

# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import * class FirstWindow(QWidget): signal = pyqtSignal(str)
def __init__(self, parent=None):
# super这个用法是调用父类的构造函数
# parent=None表示默认没有父Widget,如果指定父亲Widget,则调用之
super(FirstWindow, self).__init__(parent)
self.resize(100, 100)
self.btn = QToolButton(self)
self.btn.setText("click")
self.signal.connect(self.sinCall) def sinCall(self, text):
print("sin emit:", text)
self.btn.setText(text) def closeEvent(self, event):
result = QMessageBox.question(self,
"Confirm Exit...",
"Are you sure you want to exit ?",
QMessageBox.Yes| QMessageBox.No)
event.ignore() if result == QMessageBox.Yes:
event.accept() class SecondWindow(QWidget):
def __init__(self, parent=None):
super(SecondWindow, self).__init__(parent)
self.resize(200, 200)
self.setStyleSheet("background: black") def handle_click(self):
if not self.isVisible():
self.show() def handle_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_())

4. install Qt (可选, 方便做界面,类似winform做界面用: 界面可视化工具,可以很方便的设计UI,所见即所得)
  a. install xcode
  b. download Qt https://www.qt.io/download/ 

5. install pycharm(可选, IDE, 方便开发: 可集成Qt; Qt的ui文件转py; 直接运行python)
  a. 配置Qt Designer:   Qt的界面可视化工具,可以很方便的设计UI,所见即所得

  1. 打开 PyCharm 的设置
  2. 找到 Tools -> External Tools
  3. 点击 + -> Create Tool


      b. 配置PyUIC:   这个工具可以把Qt Designer的UI文件,转换成Py文件

    python3 -m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py

    c. 右键菜单中选择 External Tools 即可         
    d. 配置 pyrcc (安装完python3以后就有了)

    pyrcc5 resources.qrc -o resources.py

    使用

    resource.qrc
    <!DOCTYPE RCC>
    <RCC version="1.0">
    <qresource prefix="/img">
    <file alias="a.png">./img/a.png</file>
    <file alias="b.png">./img/b.png</file>
    </qresource>
    </RCC> pyrcc5 img_rcc.qrc -o img.py # 导入这个文件,会自动调用资源初始化函数
    from img.py import *
    # 使用资源的时候 访问的文件名 即 qrc里的 :prefix+alias ,例如
    img = QPixmap(":/img/a.png")

6.install pyinstaller (可选, python转可执行文件:exe, pkg))

pip3 install pyinstaller
pyinstaller -F -w {PyFile}.py

mac install PyQt5的更多相关文章

  1. Mac Python PyQt5 环境搭建

    pip install pyqt5 测试开发环境 在Terminal里敲下以下代码,如果没有报错就说明安装成功了. python -c "import PyQt5" 或是如下图,导 ...

  2. mac 安装PyQt5

    PyQt5官方安装教程指出2种安装方法: Installing from Wheels Building and Installing from Source 网上搜罗的大多是按照第二种方法安装的,本 ...

  3. react native mac install

    Mac上使用react native tips: 1. 安装Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/ ...

  4. mac install wget

    没有Wget的日子是非常难过的,强大的Mac OS 下安装Wget非常简单 下载一个Wget的源码包,http://www.gnu.org/software/wget/ ftp下载地址:ftp://f ...

  5. mac install: /usr/bin/unrar: Operation not permitted

    按照教程mac下解压缩rar文件工具-rarosx(免费),在mac上安装rar,在执行命令 sudo install -c -o $USER unrar /bin 出现错误:install: /bi ...

  6. mac install php dev

    环境开发配置 mysql 下载mysql压缩包.tar.gz 解压 mv mysql_5.7.10_osx... /usr/local/mysql sudo chown -R root:wheel / ...

  7. mac install brew

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

  8. java mac install

    http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A1096855 This page descri ...

  9. mac install telnet

    问题: -bash: telnet: command not found -bash: brew: command not found 解决: /usr/bin/ruby -e "$(cur ...

随机推荐

  1. pat1006. Sign In and Sign Out (25)

    1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  2. HDU 2795——Billboard——————【单点更新、求最小位置】

    Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  3. CSS3 -webkit-transform(元素变换)

    CSS3 -webkit-transform(元素变换)   -webkit-transform:none | 类型 类型:scale:缩放,1为原始大小.scale(x).正数放大,负数缩小.属性值 ...

  4. PHP file_put_contents() 函数

    file_put_contents() 函数把一个字符串写入文件中. 与依次调用 fopen(),fwrite() 以及 fclose() 功能一样. 语法如下 file_put_contents(f ...

  5. Vector 、ArrayList、LinkedList比较

    这三者都可以随机访问,也就是支持通过索引查找数据. 都是有序(可以实现元素怎么进怎么出) Vector和ArrayList比较 相同之处 1 它们都是List 它们都继承于AbstractList,并 ...

  6. CSS文字有关属性

    font-size|family|weight|style 大小字体加粗斜体 color|opacity 颜色透明度 height+line-height:垂直居中 overflow:hidden|v ...

  7. JSP初学者1

    native2ascii.exe 是 Java 的一个文件转码工具,是将特殊各异的内容 转为 用指定的编码标准文体形式统一的表现出来,它通常位于 JDK_home\bin 目录下, 安装好 Java ...

  8. 防反编译、混淆文件proguard.cfg与proguard-project.txt详解

    在新版本的ADT创建项目时,混码的文件不再是proguard.cfg,而是project.properties和proguard-project.txt. 如果需要对项目进行全局混码,只需要进行一步操 ...

  9. matlab练习程序(演化策略ES)

    还是这本书上的内容,不过我看演化计算这一章是倒着看的,这里练习的算法正好和书中介绍的顺序是相反的. 演化策略是最古老的的演化算法之一,和上一篇DE算法类似,都是基于种群的随机演化产生最优解的算法. 算 ...

  10. SpringMvc-helloword

    说明:在此只说明helloword的简单实现,通过helloword例子先了解springMvc是这样工作的,然后在一步步的研究原理 配置web.xml 1.配置servlet servlet-cla ...