python的gui框架pyside的安装配置教程

(一)说在前面

python自带了gui模块tkinter,只是界面风格有些老旧。另外就是各种gui框架了。

之前安装过wxpython,并做了简单的界面。遂最近又重新搜索了一下网上关于python gui框架的问题,发现还是qt呀。

python的qt有pyqt和pyside吧。pyqt 是商业及 gpl 的版权, 而 pyside 是 lgpl。大意也就是pyqt开发商业软件是要购买授权的,而pyside则不需要。二者代码基本一致,修改下import 基本剩余的代码皆可通用。所以毫不犹豫的选择了pyside。

(二)pyside的安装

(1)比较快捷省事的安装

dizzy@dizzy-pc:~$ sudo add-apt-repository ppa:pyside

you are about to add the following ppa to your system:
official ubuntu packages for pyside qt bindings.

dizzy@dizzy-pc:~$ sudo apt-get update

# … …
dizzy@dizzy-pc:~$ sudo apt-get install python-pyside
reading package lists… done
building dependency tree
reading state information… done
the following extra packages will be installed:
libphonon4 libpyside1.1 libqt4-help libqt4-scripttools libqt4-test
libqtwebkit4 libshiboken1.1 phonon phonon-backend-gstreamer
python-pyside.phonon python-pyside.qtcore python-pyside.qtdeclarative
python-pyside.qtgui python-pyside.qthelp python-pyside.qtnetwork
python-pyside.qtopengl python-pyside.qtscript python-pyside.qtsql
python-pyside.qtsvg python-pyside.qttest python-pyside.qtuitools
python-pyside.qtwebkit python-pyside.qtxml

(2)测试是否安装成功

dizzy@dizzy-pc:~$ python

python 2.7.3 (default, feb 27 2014, 20:00:17)
[gcc 4.6.3] on linux2
type “help”, “copyright”, “credits” or “license” for more information.

>>> import pyside
>>> dir(pyside)

代码如下:

[‘__all__’, ‘__builtins__’, ‘__doc__’, ‘__file__’, ‘__name__’, ‘__package__’, ‘__path__’, ‘__version__’, ‘__version_info__’]

>>> pyside.__version__

‘1.1.2’

>>> pyside.qtcore.__version__

‘4.8.1’

(三)pyside初试

# -*- coding: utf-8 -*-
# import pyside classes
import sys
from pyside.qtcore import *
from pyside.qtgui import *
# create a qt application
app = qapplication(sys.argv)
# create a label and show it
label = qlabel(“hello world”)
label.show()
# enter qt application main loop
app.exec_()
sys.exit()

这样运行就可以看到一个最简单的窗口了。hello world .

(四)hello,pyside
第一个使用pyside的示例,新建一个hello.py文件,输入以下内容:

# import pyside classes
import sys
from pyside.qtcore import *
from pyside.qtgui import *
# create a qt application
app = qapplication(sys.argv)
# create a label and show it
label = qlabel(“hello world”)
label.show()
# enter qt application main loop
app.exec_()
sys.exit()

双击该文件,运行结果:

2016216174849372.jpg (144×52)

Posted in 未分类

发表评论