Python的GUI架構PySide的安裝配置教程

來源:互聯網
上載者:User
(一)說在前面

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-pysideReading package lists... DoneBuilding dependency tree    Reading state information... DoneThe 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 linux2Type "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 classesimport sysfrom PySide.QtCore import *from PySide.QtGui import *  # Create a Qt application app = QApplication(sys.argv)# Create a Label and show itlabel = QLabel("Hello World")label.show()# Enter Qt application main loopapp.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() 

雙擊該檔案,運行結果:

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.