1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| # -*- coding: utf-8 -*-
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from sys import *
class Ui_Form(object):
def BtnCD(self):
if self.drap:
self.pushButton.setIcon(QIcon(''))
self.drap = False
else:
self.pushButton.setIcon(QIcon('./Images/drap.png'))
self.pushButton.setIconSize(QSize(80, 80))
self.drap = True
def BtnCG(self):
if self.mine:
self.pushButton.setIcon(QIcon(''))
self.mine = False
else:
self.pushButton.setIcon(QIcon('./Images/mine.png'))
self.pushButton.setIconSize(QSize(80, 80))
self.mine = True
def setupUi(self, Form):
#region Form
Form.setObjectName("Form")
Form.resize(100, 100)
#endregion
#region variables
self.drap = False
self.mine = False
#endregion
#region PushButton
self.pushButton = QPushButton(Form)
self.pushButton.setGeometry(QRect(10, 10, 80, 80))
self.pushButton.setText("")
self.pushButton.setObjectName("pushButton")
self.pushButton.setContextMenuPolicy(Qt.CustomContextMenu)
self.pushButton.customContextMenuRequested.connect(self.BtnCD)
self.pushButton.clicked.connect(self.BtnCG)
#endregion
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Demo"))
if __name__ == "__main__":
app = QApplication(argv)
Form = QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
exit(app.exec_()) |
Partager