Sunday, October 4, 2015

Install PyQt4 on Raspberry Pi

o install PyQt4 for Python 2 on Raspberry Pi
$ sudo apt-get install python-qt4

for Python 3
$ sudo apt-get install python3-pyqt4



Example: hello.py
import sys
from PyQt4.QtGui import *

from PyQt4.QtCore import QT_VERSION_STR
from PyQt4.Qt import PYQT_VERSION_STR
from sip import SIP_VERSION_STR

a = QApplication(sys.argv)       

w = QWidget()
w.resize(320, 240)
w.setWindowTitle("Hello World!") 

label = QLabel()
info = "Qt version:" + QT_VERSION_STR + \
       "\nSIP version:" + SIP_VERSION_STR + \
       "\nPyQt version:" + PYQT_VERSION_STR
label.setText(info)

hbox = QHBoxLayout()
hbox.addWidget(label)
w.setLayout(hbox)

w.show() 
 
sys.exit(a.exec_())


PyQt4 hello.py run on Python 2

PyQt4 hello.py run on Python 3

No comments: