import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton class Example(QWidget): def __init__(self): super().__ Init__ () self. initUI () # Give the interface drawing to InitUi method def initUI (self): # Set the position and size of the window self. setGeometry (300, 300, 300, 220) # Set the window title self. setwindowTitle ('QPushButton ') # Define and set the control QPushButton self. button=QPushButton (self) self. button. setStyleSheet ("QPushButton {border image: url (img/1. png)}" "QPushButton: over {border image: url (img/1_1. png)}" "QPushButton: pressed {border image: url (img/1_1. png)}") # Set the position and size of the control QPushButton self. button. setGeometry (100, 100, 50, 50) if __name__=='__main__ ': # Create applications and objects app=QApplication (sys. argv) ex=Example() ex.show() sys. exit (app. exec_ ())
import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton class Example(QWidget): def __init__(self): super().__ Init__ () self. initUI() # Give the interface drawing to InitUi method self. slot_init() def initUI (self): # Set the position and size of the window self. setGeometry (300, 300, 300, 220) # Set the title of the window self. setwindowTitle ('QPushButton ') # Define and set the control QPushButton self. button=QPushButton (self) Self. button. setStyleSheet ("QPushButton {border image: url (img/1. png)}" "QPushButton: over {border image: url (img/1_1. png)}") # Set the position and size of the control QPushButton self. button. setGeometry (100, 100, 50, 50) def slot_init (self): self. button. clicked. connect (self. button_change) def button_change (self) : # The switch icon lights up self. button. setStyleSheet ('QPushButton {border image: url (img/1_1. png)} ') if __name__=='__main__': # Create applications and objects app=QApplication (sys. argv) ex=Example() ex.show() sys. exit (app. exec_ ())