为什么80%的码农都做不了架构师?>>>
(一)说在前面
Python自带了GUI模块Tkinter,只是界面风格有些老旧。另外就是各种GUI框架了。
之前安装过WxPython,并做了简单的界面。遂最近又重新搜索了一下网上关于Python GUI框架的问题,发现还是Qt呀。
Python的Qt有PyQt和PySide吧。PyQt 是商业及 GPL 的版权, 而 PySide 是 LGPL。大意也就是PyQt开发商业软件是要购买授权的,而PySide则不需要。二者代码基本一致,修改下import 基本剩余的代码皆可通用。所以毫不犹豫的选择了PySide。
接下来的这段时间,将会一边学习Pyside,一边学习Django更深层次的东西。如果还有时间,就再熟悉一下Python基础的一些东西。
(二)PySide的安装
(1)官网教程略显麻烦。
官网: http://qt-project.org/wiki/PySide
(2)比较快捷省事的安装
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
(3)测试是否安装成功
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 .
(四)PySide教程
官网教程: http://qt-project.org/wiki/PySideDocumentation
Overview of Python GUI development : http://pythoncentral.org/introduction-python-gui-development/
找到一个比较不错的教程: http://srinikom.github.io/pyside-docs/index.html
再加一个经典书籍: http://www.commandprompt.com/community/pyqt/book1 GUI Programming with Python: QT Edition