pycharm下pyqt4安装及环境配置的教程
作者:明天也要加油鸭 时间:2021-11-01 16:03:57
一、安装
首先根据自己的python版本下载pyqt4离线包,现在连接:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4
比如我地python版本是python3.5.2,我选择PyQt4‑4.11.4‑cp35‑cp35m‑win_amd64.whl
在whl文件路径下,使用pip指令安装
pip install PyQt4‑4.11.4‑cp35‑cp35m‑win_amd64.whl
静待安装完成即可
二、pycharm下环境配置
找到:File——>Settings——>Tools——>External Tools
添加QtDesigner、PyUIC、PyRcc三个工具,如下图所示:
1. QtDesigner,program填“自己的python路径\python\Lib\site-packages\PyQt4\designer.exe”,Arguments不用填,Working Directory填:$ProjectFileDir$。
2.PyUIC,program填“自己的python路径\python\python.exe”,Arguments填“-m PyQt4.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py”,Working Directory填:$ProjectFileDir$。
3. PyRcc,program填“自己的python路径\python\Scripts\pyrcc5.exe”,Arguments填“$FileName$ -o $FileNameWithoutExtension$_rc.py”,Working Directory填:$ProjectFileDir$。
三、简单使用
使用QtDesigner设计了一个简单的界面,保存为test.ui。
然后在pycharm中右击test.ui 文件,使用pyUIC生成test.py文件。
生成的test.py文件如下:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(587, 457)
self.TestBtn = QtGui.QPushButton(Form)
self.TestBtn.setGeometry(QtCore.QRect(0, 10, 75, 51))
self.TestBtn.setObjectName(_fromUtf8("TestBtn"))
self.ShowPte = QtGui.QPlainTextEdit(Form)
self.ShowPte.setGeometry(QtCore.QRect(80, 10, 491, 431))
self.ShowPte.setObjectName(_fromUtf8("ShowPte"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.TestBtn.setText(_translate("Form", "按钮", None))
self.ShowPte.setPlainText(_translate("Form", "窗前明月光,\n"
"疑是地上霜。\n"
"举头望明月,\n"
"低头思故乡。", None))
然后创建一个main.py来启动程序。
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui
from test import *
class MyWindows(QtGui.QWidget):
def __init__(self):
super(MyWindows,self).__init__()
Ui_Form().setupUi(self)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ui=MyWindows()
ui.show()
app.exec()
运行main.py文件,得到如下界面。
来源:https://blog.csdn.net/Dashi_Lu/article/details/105700838
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Golang 内存管理简单技巧详解
Python调用Zoomeye搜索接口的实现
![](https://img.aspxhome.com/file/2023/7/107177_0s.png)
sklearn+python:线性回归案例
简单了解Django应用app及分布式路由
![](https://img.aspxhome.com/file/2023/8/121888_0s.png)
关于超级链接的一些问题
![](https://img.aspxhome.com/file/UploadPic/200712/7/200712714819482s.jpg)
详解Python中的分支和循环结构
服务器端控件是如何操作的?
Python基于OpenCV实现人脸检测并保存
如何在Django配置文件里配置session链接
SQL 注入式攻击的终极防范
Python基于checksum计算文件是否相同的方法
python 数据挖掘算法的过程详解
![](https://img.aspxhome.com/file/2023/1/107481_0s.png)
零基础写python爬虫之抓取百度贴吧并存储到本地txt文件改进版
![](https://img.aspxhome.com/file/2023/0/102730_0s.png)
PHP:微信小程序 微信支付服务端集成实例详解及源码下载
![](https://img.aspxhome.com/file/2023/3/90253_0s.png)
解决Django中多条件查询的问题
教你用pyecharts绘制各种图表案例(效果+代码)
![](https://img.aspxhome.com/file/2023/8/94168_0s.png)
javascript操作ASP.NET服务器控件
python3 Scrapy爬虫框架ip代理配置的方法
![](https://img.aspxhome.com/file/2023/7/131137_0s.png)
vscode写python时的代码错误提醒和自动格式化的方法
![](https://img.aspxhome.com/file/2023/2/114682_0s.jpg)