import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton class Example(QWidget): def __init__(self): super().__init__() self.initUI() # The interface drawing is handed to InitUi's method define 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 QPushButton control self.button = QPushButton(self) self.button.setStyleSheet(“QPushButton{border-image: url(img/1.png)}” “QPushButton:hover{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() # The interface drawing is handed 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 QPushButton control self.button = QPushButton(self) self.button.setStyleSheet(“QPushButton{border-image: url(img/1.png)}” “QPushButton:hover{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_ ())