1、windows 平台搭建PyQt4+Python3+Eric6
本文省去了SIP等安装过程,故采用下载以GPL协议发布的类似于直接安装的exe 的最新版,目前PYQT官网已经不再发布EXE直接安装包,我们采用最终版本搭载Python3.4.4作为开发环境
1.1 Python3 下载地址
https://www.python.org/downloads/release/python-344/
1.2 PyQt4安装包下载地址
https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/PyQt4-4.11.4-gpl-Py3.4-Qt4.8.7-x32.exe/download
或者64位的直接安装包
https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/PyQt4-4.11.4-gpl-Py3.4-Qt4.8.7-x64.exe/download
1.4 安装过程
首先安装Python3.4.4 ,默认安装在 C:\Python34 文件下,建议安装全部组件,这里注意只要在第一步勾选添加到系统环境路径中即可。
再次安装PyQt4
安装程序会自动识别Python的安装路径,一般默认就是就是Python的安装目录。
1.5测试PyQt4是否安装成功
在Python开发环境下,执行下面的代码,查看是否生成了对话框
from __future__ import division
import sys
from math import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.browser = QTextBrowser()
self.lineedit = QLineEdit("Type an expression and press Enter")
self.lineedit.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
self.setLayout(layout)
self.lineedit.setFocus()
self.connect(self.lineedit, SIGNAL("returnPressed()"),
self.updateUi)
self.setWindowTitle("Calculate")
def updateUi(self):
try:
text = self.lineedit.text()
self.browser.append("%s = <b>%s</b>" % (text, eval(text)))
except:
self.browser.append(
"<font color=red>%s is invalid!</font>" % text)
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
最终生成的是一个计算器小程序