3

PyQt5系列教程(二):基本功能

 3 years ago
source link: https://xushanxiang.com/2019/08/pyqt5-series-tutorial-2-basic-functions.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PyQt5系列教程(二):基本功能

作者: haiyang 分类: Python 发布时间: 2019-08-01 09:57

这一节主要介绍PyQt5的基础知识

简单的例子

PyQt5是 一种高级的语言,底层已经实现了创建的基本功能。

首先我们要安装PyQt5:

win系统下安装PyQt5的命令是:pip install pyqt5 pip install pyqt5_tools

Ubuntu系统下安装PyQt5的命令是: pip3 install pyqt5 pip3 install pyqt5_tool

下面几行代码就能显示出一个基本窗口如下:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
if name == ‘main‘:
#每一pyqt5应用程序必须创建一个应用程序对象。sys.argv参数是一个列表,从命令行输入参数。
app = QApplication(sys.argv)
#QWidget部件是pyqt5所有用户界面对象的基类。他为QWidget提供默认构造函数。默认构造函数没有父类。
w = QWidget()
#resize()方法调整窗口的大小。这离是250px宽150px高
w.resize(550, 351)
#move()方法移动窗口在屏幕上的位置到x = 300,y = 300坐标。
w.move(300, 300)
#设置窗口的标题
w.setWindowTitle(‘Simple’)
#显示在屏幕上
w.show()

#系统exit()方法确保应用程序干净的退出
#的exec_()方法有下划线。因为执行是一个Python关键词。因此,exec_()代替
sys.exit(app.exec_())

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK