mac下安装pyside2

环境:mac已经安装了python3.5,pip3.5
IDE:PyCharm

安装pyside2

1
pip3.5 install --index-url=http://download.qt.io/snapshots/ci/pyside/5.9/latest/ pyside2 --trusted-host download.qt.io

简单实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 1st.py

import sys
from PySide2 import QtGui
from PySide2 import QtWidgets

app = QtWidgets.QApplication(sys.argv)

wid = QtWidgets.QWidget()
wid.resize(250, 150)
wid.setWindowTitle('Simple')
wid.show()

sys.exit(app.exec_())


面向对象写法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
# -*- coding: utf-8 -*-


import sys
from PySide2 import QtGui
from PySide2 import QtWidgets

class Example(QtWidgets.QWidget):

def __init__(self):
super(Example, self).__init__()

self.initUI()

def initUI(self):

self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Icon')
self.setWindowIcon(QtGui.QIcon('icon.png'))

self.show()

def main():

app = QtWidgets.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())


if __name__ == '__main__':
main()