本文已参与「新人创作礼」活动,一起开启掘金创作之路。
学习PyQt操作中遇到的问题
之前有项目需要使用到PyQt,在ubuntu系统中安装软件,和vscode中调用都碰到了不少问题,在此记录一下。
VScode运行PyQt代码出错
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
解决方案:由于缺少相关的依赖库,所以程序运行出错,在Ubuntu下直接通过如下的命令安装即可:
sudo apt-get install libxcb-xinerama0
安装完成之后即可启动程序
ubuntu下安装qtDesigner
终端执行
designer没有弹出软件界面
sudo apt-get install qt5-default qttools5-dev-tools
在终端执行designer就可以打开qt designer界面。
pyqt5 'QWidget' object has no attribute 'setCentralWidget'
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QWidget()
ui = Ui_MainWindow()
ui.setupUi(widget)
widget.show()
sys.exit(app.exec_())
将QtWidgets.QWidget()修改为QtWidgets.QMainWindow()
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(widget)
widget.show()
sys.exit(app.exec_())
Python加载json数据
import json
def resolveJson(path):
file = open(path, "rb")
fileJson = json.load(file)
field = fileJson["field"]
futures = fileJson["futures"]
type = fileJson["type"]
name = fileJson["name"]
time = fileJson["time"]
return (field, futures, type, name, time)
def output():
result = resolveJson(path)
print(result)
for x in result:
for y in x:
print(y)
path = r"C:\Users\dell\Desktop\kt\test.json"
output()
注意函数返回多个值时返回的是一个元组tuple; 对一个字符串进行for循环的时候会对每个字符进行遍历
JSON函数
使用 JSON 函数需要导入 json 库:import json。
| 函数 | 描述 |
|---|---|
| json.dumps | 将 Python 对象编码成 JSON 字符串 |
| json.loads | 将已编码的 JSON 字符串解码为 Python 对象 |
VSCode配置Python、PyQt5、QtDesigner环境并创建一个ui界面测试
ImportError: No module named PyQt5
需要安装PyQt5
安装方式:
sudo apt-get install python-pyqt5-dbg
Linux pyinstaller 打包问题 enable-shared
Linux pyinstaller 打包问题 enable-shared
pyinstaller -F --hidden-import="pydicom.encoders.gdcm" --hidden-import="pydicom.encoders.pylibjpeg" main.py
ubuntu安装python_Ubuntu下,用Pyinstaller打包桌面系统时,你踩坑了没
Ubuntu下批处理转换jpg 2 png格式
mogrify -format png *.jpg
Ubuntu查看图片分辨率信息
identify xxx.jpg
Linux一条命令改变图片大小
convert -resize 100x100 test.jpg test-new.jpg