Skip to content

Instantly share code, notes, and snippets.

@nikicc
Last active June 23, 2016 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikicc/468543a494ea1a14a4a82e605a9d99de to your computer and use it in GitHub Desktop.
Save nikicc/468543a494ea1a14a4a82e605a9d99de to your computer and use it in GitHub Desktop.
PyQt Image As Checkbox Button
import sys
from PyQt4 import QtCore
from PyQt4.QtGui import *
def abu():
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(abu)
button.setStyleSheet('border:none')
layout.addWidget(button)
icon1 = QIcon("off_button.png")
icon2 = QIcon("on_button.png")
button.setIcon(icon1)
button.setIconSize(QtCore.QSize(30, 30))
widget.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment