如何用Python和PyQt构建一个图形用户界面?

2026-06-09 14:345阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计719个文字,预计阅读时间需要3分钟。

如何用Python和PyQt构建一个图形用户界面?

1. 安装PyQT5及QT Designer工具包,使用清华大学源,安装步骤快捷。 bash pip install PyQt5 -i https://pypi.tuna.tsinghua.edu.cn/simple pip install PyQt5-tools -i https://pypi.tuna.tsinghua.edu.cn/simple

1.安装PyQT5 以及QT Designer工具包,这里使用清华大学的源,安装快一些。

pip install PyQt5 -i pypi.tuna.tsinghua.edu.cn/simple
pip install PyQt5-tools -i pypi.tuna.tsinghua.edu.cn/simple


2.安装PyQt5 会根据Python的安装路径自动进行安装,不需要修改,安装好以后,测试安装是否成功。写下面的代码,运行看运行是否正确。

import sys
from PyQt5 import QtWidgets
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
w.resize(400, 200)
w.setWindowTitle("hello lyshark")
w.show()
exit(app.exec_())

接着直接双击运行,如果成功执行,那么会看到一个窗体生成了。

阅读全文

本文共计719个文字,预计阅读时间需要3分钟。

如何用Python和PyQt构建一个图形用户界面?

1. 安装PyQT5及QT Designer工具包,使用清华大学源,安装步骤快捷。 bash pip install PyQt5 -i https://pypi.tuna.tsinghua.edu.cn/simple pip install PyQt5-tools -i https://pypi.tuna.tsinghua.edu.cn/simple

1.安装PyQT5 以及QT Designer工具包,这里使用清华大学的源,安装快一些。

pip install PyQt5 -i pypi.tuna.tsinghua.edu.cn/simple
pip install PyQt5-tools -i pypi.tuna.tsinghua.edu.cn/simple


2.安装PyQt5 会根据Python的安装路径自动进行安装,不需要修改,安装好以后,测试安装是否成功。写下面的代码,运行看运行是否正确。

import sys
from PyQt5 import QtWidgets
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
w.resize(400, 200)
w.setWindowTitle("hello lyshark")
w.show()
exit(app.exec_())

接着直接双击运行,如果成功执行,那么会看到一个窗体生成了。

阅读全文