6

PyQt5系列教程(二):基本功能之程序的图标

 3 years ago
source link: https://xushanxiang.com/2019/08/pyqt5-series-tutorial-2-icons-for-basic-function-programs.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.
neoserver,ios ssh client

PyQt5系列教程(二):基本功能之程序的图标

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

应用程序的图标

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon
 
 
class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI() #界面绘制交给InitUi方法
        
        
    def initUI(self):
        #设置窗口的位置和大小
        self.setGeometry(300, 300, 300, 220)  
        #设置窗口的标题
        self.setWindowTitle('Icon')
        #设置窗口的图标,引用当前目录下的web.png图片
        self.setWindowIcon(QIcon('web.png'))        
        
        #显示窗口
        self.show()
        
        
if __name__ == '__main__':
    #创建应用程序和对象
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_()) 

前面的例子是在程序风格。Python编程语言支持程序和面向对象编程风格。Pyqt5使用OOP编程。

class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        ...

面向对象编程有三个重要的方面:类、变量和方法。这里我们创建一个新的类为Examle。Example继承自QWidget类。

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

发表评论 取消回复

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK