PyQT_learning/TechWithTim/tutorial1.py

41 lines
952 B
Python
Raw Normal View History

2021-12-08 18:48:43 +01:00
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
2021-12-08 22:12:30 +01:00
2021-12-08 18:48:43 +01:00
class MyWindow(QMainWindow):
clicked_times = 0
2021-12-08 22:12:30 +01:00
2021-12-08 18:48:43 +01:00
def __init__(self):
super(MyWindow, self).__init__()
self.setGeometry(200, 200, 300, 300)
self.setWindowTitle("Armando's First test !")
self.initUI()
def initUI(self):
self.label = QtWidgets.QLabel(self)
self.label.setText("This is label")
self.label.move(50, 50)
self.b1 = QtWidgets.QPushButton(self)
self.b1.setText("Click aqui !")
self.b1.clicked.connect(self.clicked)
def clicked(self):
self.clicked_times += 1
self.label.setText("You pressed the button {} times".format(self.clicked_times))
self.update()
def update(self):
self.label.adjustSize()
2021-12-08 22:12:30 +01:00
2021-12-08 18:48:43 +01:00
def window():
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec())
window()