How to add my Labe by mouse left clicking, for example, in the following code, how to call a Todo function by clicking in any part of my app window and add lable here?
import sys
from PyQt5.QtWidgets import(QApplication, QLabel, QWidget)
import sys
class MouseTracker(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.setMouseTracking(True)
def initUI(self):
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Mouse Tracker')
self.show()
def mousePressEvent(self, event):
print("x , y")
def todo(self):
self.label = QLabel('This is label', self)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MouseTracker()
sys.exit(app.exec_())