2024-04-25 05:24:09 发布
网友
Python是否可以使用image作为复选框(在PyQT制作的GUI应用程序中)?例如,有一个蓝色圆圈的图像,当你点击它时,它变成红色。在
以下是解决此难题的方法:
import sys from PyQt4 import QtCore from PyQt4.QtGui import * def chk(): global button, checked checked = not checked ic = icon1 if checked else icon2 button.setIcon(ic) app = QApplication(sys.argv) widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) checked = True button = QPushButton() button.setFlat(True) button.clicked.connect(chk) button.setStyleSheet('border:none') layout.addWidget(button) icon1 = QIcon("off.png") icon2 = QIcon("on.png") button.setIcon(icon1) button.setIconSize(QtCore.QSize(30, 30)) widget.show() app.exec_()
以下是解决此难题的方法:
相关问题 更多 >
编程相关推荐