前言
按钮控件是图形用户界面(GUI)中常用的交互元素,用于触发特定的事件或行为。在Qt框架中,QPushButton和QToolButton是两种常用的按钮控件。
后边我们将以test.png为按钮图标,对比使用两种按钮控件。
普通按钮控件(QPushButton)
QPushButton是一个标准的按钮控件,用户可以点击它来触发某个动作。当按钮被点击时,它会发出一个信号,可以通过连接到一个槽函数来执行某个动作。
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import sys
class Window(QWidget):
def __init__(self):
super(Window, self).__init__()
self.button = QPushButton('demo')
self.button.setIcon(QIcon('test.png'))