from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QPushButton, QApplication app = QApplication([]) icon = QIcon("icon.png") button = QPushButton(icon, "Button") button.show() app.exec_()
from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QAction, QApplication, QMainWindow class MainWindow(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.toolbar = self.addToolBar('Exit') exitAction = QAction(QIcon('exit.png'), 'Exit', self) exitAction.triggered.connect(self.close) self.toolbar.addAction(exitAction) self.show() app = QApplication([]) mainWin = MainWindow() app.exec_()In this example, we are creating a `QMainWindow` with a toolbar that has an "Exit" button. The `QIcon` class is used to load an image file named "exit.png" and set it as the icon for the "Exit" action. When the action is triggered, it closes the main window. The package/library that is being used here is `PyQt5`.