|
|
| PyQt4-4.11.4-gpl-Py3.4-Qt5.5.0-x64.exe | Windows 64 bit installer 를 다운받아 설치하면 폼 디자이너도 제공함. Python의 site-packages에 PyQt4도 자동 등록됨. |
예1) 윈도우 창 호출
from PyQt4 import QtGui
import sys
class MyForm(QtGui.QWidget):
def __init__(self, parent=None):
super(MyForm, self).__init__(parent)
helloLabel = QtGui.QLabel("자료 입력:")
helloLineEdit = QtGui.QLineEdit()
mainLayout = QtGui.QGridLayout()
mainLayout.addWidget(helloLabel, 0, 0)
mainLayout.addWidget(helloLineEdit, 0, 1)
self.setLayout(mainLayout)
self.setWindowTitle("My Python App")
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
my = MyForm()
my.show()
sys.exit(app.exec_())
예2) Qt Designer로 작성 후 파이썬에서 호출
http://pythonforengineers.com/your-first-gui-app-with-python-and-pyqt/
import sys
from PyQt4 import QtGui, uic
qtCreatorFile = "my.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
Centos7에서 QT 디자이너 설치
[root@localhost ~]# yum -y install pyqt4
[root@localhost ~]# yum -y install qt4-designer
QT 라이브러리 설치
[root@localhost ~]# wget http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/PyQt-x11-gpl-4.11.4.tar.gz
[root@localhost ~]# wget http://sourceforge.net/projects/pyqt/files/sip/sip-4.17/sip-4.17.tar.gz
[root@localhost ~]# tar xvzf PyQt-x11-gpl-4.11.4.tar.gz
[root@localhost ~]# tar xvzf sip-4.17.tar.gz
[root@localhost ~]# cd sip-4.17
[root@localhost sip-4.17]# python3.4 configure.py
[root@localhost sip-4.17]# make
[root@localhost sip-4.17]# make install
[root@localhost sip-4.17]# cd
[root@localhost ~]# cd PyQt-x11-gpl-4.11.4
[root@localhost PyQt-x11-gpl-4.11.4]# python3.4 configure.py -q /usr/bin/qmake-qt4
[root@localhost PyQt-x11-gpl-4.11.4]# make
[root@localhost PyQt-x11-gpl-4.11.4]# make install
[root@localhost PyQt-x11-gpl-4.11.4]# cd
[root@localhost ~]# python3.4
Python 3.4.4 (default, Jan 8 2016, 12:01:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtCore, QtGui
>>> import sys
>>> from PyQt4.QtGui import *
>>> app = QApplication(sys.argv)
>>> button = QPushButton("Hello World", None)
>>> button.show()
>>> app.exec_()
--------------------------------------------------------------------------------------------
참고 : 만약에 python 3.3 rpm 설치하고 싶다면 루트로 로그인한 후
[root@localhost ~]# python -V
[root@localhost ~]# yum -y install scl-utils
[root@localhost ~]# rpm -Uvh https://www.softwarecollections.org/en/scls/rhscl/python33/epel-7-x86_64/download/rhscl-python33-epel-7-x86_64.noarch.rpm
[root@localhost ~]# yum -y install python33
[root@localhost ~]# scl enable python33 bash
[root@localhost ~]# python -V
[root@localhost ~]# easy_install pip