17_pyqt环境搭建


title: pyqt环境搭建
urlname: 17_pyqt环境搭建
author: vsyour
language: zh-CN
date: 2017-05-10 03:03:03
tags: [python]
categories: 网络安全

pyqt环境搭建
QQ群:397745473

python 版本选择

.选择python 2.x

python 开发的easy 模式

原生的idle并不好用.
可以选用ipython,支持自动补全.自动缩进,支持bash shell
内部很多有用的功能和函数.

pythonxy

集成python 科技计算包.如numpy,matplotlib,spyder
缺点:现在更新比较慢了.

python EPD

商业版本,不建议用

Anaconda

建议使用
内部很多新版本的科学计算包,由python之父维护.
安装前卸载其他python解释器
下载地址:https://www.continuum.io/downloads/
装完后再去pyqt官网下载一个重新安装pyqt.这样才能编译成功.
安装ERIC4 F2运行
安装

Eric4

首次运行需配置环境

eclipse + pydev

安装jdk,java运行环境
在eclipse中安装pydev
1.去官网下载eclipse
2.安装Pydev
输入网址,选第一个勾上就行了.
配置python解释器路径

布局器的使用
垂直布局
横向布局
网格布局
窗体布局

lebel控件
主要目的是为了显示信息,可以发射信号

环境搭建

1.卸载掉其他的python环境.
2.下载Anaconda2,下载地址:https://repo.continuum.io/archive/Anaconda2-4.3.1-Windows-x86_64.exe
建议到网官下载最新版本,如果速度慢可以使用迅雷或者先下载到网盘里再用客户端下载,这样速度比较快.
双击:E:\BaiduYunDownload\Anaconda2-4.3.1-Windows-x86_64.exe
安装路:d:\Anaconda2
其他的默认就好了

3.重新下载并安装pyqt
到pyqt官网上下一个再装一遍,把Anaconda2不太好用的这个覆盖掉.
https://sourceforge.net/projects/pyqt/files/PyQt4/
http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe
这里需要注意找对版本.比如我的用的是python 2.7,64位的系统,就需要找2.7的版本.

下载Eric6:
https://sourceforge.net/projects/eric-ide/files/latest/download
https://sourceforge.net/projects/eric-ide/files/latest/download
http://netix.dl.sourceforge.net/project/eric-ide/eric6/stable/6.1.4/eric6-6.1.4.zip
4.将eric6-6.1.4.zip解压,找到install.py, 双击会自动安装Eric

问题解决

错误提示信息:

C:\TDDownload\PyQt4_gpl_win-4.12>python D:\Anaconda2\eric6-17.05\eric\eric6.py
Error in sys.excepthook:
Traceback (most recent call last):
  File "D:\Anaconda2\eric6-17.05\eric\eric6.py", line 149, in excepthook
    import Utilities
  File "D:\Anaconda2\eric6-17.05\eric\Utilities\__init__.py", line 62, in <module>
    from PyQt5.Qsci import QSCINTILLA_VERSION_STR, QsciScintilla
ImportError: No module named Qsci

Original exception was:
Traceback (most recent call last):
  File "D:\Anaconda2\eric6-17.05\eric\eric6.py", line 377, in <module>
    main()
  File "D:\Anaconda2\eric6-17.05\eric\eric6.py", line 268, in main
    if not Globals.checkBlacklistedVersions():
  File "D:\Anaconda2\eric6-17.05\eric\Globals\__init__.py", line 112, in checkBlacklistedVersions
    from PyQt5.Qsci import QSCINTILLA_VERSION_STR
ImportError: No module named Qsci

这是因为pyqt装的版本不对.所以就会出现上面的错误,重新安装正确的版本就解决了.

这里还有可能碰到一个问题:
总是报Qsci没有安装。经过测试很多次。发现了。先装个最新版的3.5pyqt,再卸载掉。再装上面的这个就没有问题了。

提示如下信息为正常:

C:\Users\vsyour>python D:\Anaconda2\eric6-6.1.4\install.py
Checking dependencies
Python Version: 2.7.13
Found PyQt4
Found pyuic4
Found QScintilla2
Found QtGui
Found QtNetwork
Found QtSql
Found QtSvg
Qt Version: 4.8.7
sip Version: 4.16.8
PyQt Version: 4.11.4
QScintilla Version: 2.9
All dependencies ok.

Cleaning up old installation ...

Creating configuration file ...

Compiling user interface files ...

Compiling source files ...

Installing eric6 ...

Installation complete.

Press enter to continue...

配置:

执行 install.py
1.API处选python,并编译一下.
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vGyQmjpt-1680053540992)(null)]

2.自动补全
3.自动补全的下一项点击from…

pyqt使用笔记

加入槽函数.

测试提示信息

my_button=QMessageBox.information(self,'infomation',u'提示信息',)
my_button=QMessageBox.information(self, u'提示信息框', u'提示内容',)

1.加入"pushButton_8"
2.点保存.
3.编译.
4.加入槽函数.选择"on_pushButton_8_clicked"事件

from PyQt4.QtCore import *
from PyQt4.QtGui import *

在py执行文件的头部加入消息提示包,不然会报错的.
5.加入上面的代码,执行测试.

询问框

my_button=QMessageBox.question(self, u'询问框标题', u'询问内容', )
my_button=QMessageBox.question(self, u'询问框标题', u'询问内容', 'OK','cancel',u'我也不知道')

警告信息

my_button=QMessageBox.warning(self, u'警告提示框', u'警告内容')
my_button=QMessageBox.warning(self, u'警告提示框', u'警告内容', 'ok', 'cancel', 'nonono')
print my_button

严重警告对话框

my_button=QMessageBox.critical(self, u'严重警告', u'严重警告内容!', u'操作1', u'操作2', u'操作3')

测试发现这个操作最多是3个,多了就会报错了.

关于对话框

my_button=QMessageBox.about(self, u'关于标题', u'关于内容')

about QT

my_button=QMessageBox.aboutQT(self, u'aboutQT')

16.运行时获取用户输入,弹出一个界面(上)

获取字符串

my_str, ok=QInputDialog.getText(self, u'提示标题', u'请输入参数:',QLineEdit.Normal,  u'框内内容')
        print unicode(my_str)
        print ok

获取整数

my_str, ok=QInputDialog.getInteger(self, u'提示标题', u'请输入整数:',30, 0, 100)
        print unicode(my_str)
        print ok

下拉框

    @pyqtSignature("")
    def on_pushButton_15_clicked(self):
        """
        Slot documentation goes here.
        """
        # TODO: not implemented yet
        my_list=QStringList()
        my_list.append(u'选择1')
        my_list.append(u'选择2')
        my_list.append(u'选择3')
        my_list.append(u'选择4')
        my_list.append(u'选择5')
        my_list.append(u'选择6')
        
        my_str, ok=QInputDialog.getItem(self, u'提示标题', u'提示内容', my_list)
        self.textBrowser.append(unicode(my_str)    )
        print unicode(my_str)        
        print ok

定制对话框

需要先建立一个Ui,把内容放到原来的里面就行了.
注意:记得要把下面这句给复制上,不然弹不出来.其他的就没什么需要注意的了

from Ui_001 import Ui_Dialog

图片控件

1.拖入"graphicsView"控制
2.把资源添加到资源浏览器中
3.点控件,右键,编辑样式表–点添加资源右边的小三角–选中间那个(第一个是加背景图片,第二个是可伸缩的,第三个是按原图大小显示)
4.生成py文件.点击resource–add resource–再编译一下

这里需要注意的是加资源的时候路径不要有中文 .不然会编译不成功

实现点击图片打开网站

1.在MainWindow中加入一个自定义的槽函数
2.

self.graphicsView.mousePressEvent=self.my_clicked

3.导入webbrowser包

import webbrowser

实现这个点击的方法

    def my_clicked(self, e):
        print 'chicked!'
        webbrowser.open('http://www.baidu.com')
        

更改图片的显示

使用lable显示图片
只需要在点击事件里更改对应标签的属性就行了.
如:

self.graphicsView.setStyleSheet(_fromUtf8("border-image: url(:/pic/543ba83533fa828b4292640bfd1f4134960a5aaf.jpg);"))

20.启动界面,来个炫酷的出场

加一个图片资源…可以转到pycharm中去操作了.
eric主要用来做UI的编辑

python程序打包

用pyinstaller打包
建议到32位电脑上打包
1.打包成文件夹 执行:pyinstaller xxx.py
2.打包成单个文件 执行:pyinstaller -F xxx.py
3.打包成单个文件,windows窗口程序. 执行:pyinstaller -F -w xxx.py
3.加图标. 执行:pyinstaller -F -w -i x:\xxx\xxx\xx.ico xxx.py

注意:
1.程序只能在英文目录下打包,并在英文路径下运行
2.打包后的名字必须用英文名字

QQ群:397745473
thon程序打包 #
用pyinstaller打包
建议到32位电脑上打包
1.打包成文件夹 执行:pyinstaller xxx.py
2.打包成单个文件 执行:pyinstaller -F xxx.py
3.打包成单个文件,windows窗口程序. 执行:pyinstaller -F -w xxx.py
3.加图标. 执行:pyinstaller -F -w -i x:\xxx\xxx\xx.ico xxx.py

注意:
1.程序只能在英文目录下打包,并在英文路径下运行
2.打包后的名字必须用英文名字

QQ群:397745473

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
回答: 搭建Python PyQt5环境的步骤如下: 1. 首先,你需要安装PyQt5。PyQt5是一个创建Python GUI应用程序的工具包,是C++的Qt和Python结合的一个产物。你可以使用pip命令来安装PyQt5,例如在命令行中输入:pip install pyqt5。\[2\] 2. 如果你需要使用Qt Designer来设计图形界面,你还需要安装PyQt5的工具包。你可以使用pip命令来安装PyQt5工具包,例如在命令行中输入:pip install pyqt5-tools。\[2\] 3. 如果你在安装PyQt5时遇到了一些问题,可以尝试使用国内资源来加速安装。你可以使用以下命令来安装PyQt5和PyQt5工具包:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyqt5和pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyqt5-tools。\[3\] 4. 安装完成后,你就可以开始使用PyQt5来开发Python GUI应用程序了。你可以使用Qt Designer来设计图形界面,然后使用PyUIC将图形界面相关资源转换成Python代码。最后,你可以使用PyQt5类库来编写应用程序的逻辑部分。\[2\] 希望以上信息对你有帮助!如果还有其他问题,请随时提问。 #### 引用[.reference_title] - *1* [【pythonPyQt5的环境搭建](https://blog.csdn.net/weixin_42231048/article/details/123297848)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [PyQt5开发环境搭建](https://blog.csdn.net/pan_chensir/article/details/113988594)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [pyQt5环境搭建](https://blog.csdn.net/baidu_24752135/article/details/123265153)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vsyour

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值