PyQT_learning/TechWithTim/tutorial1.py

39 lines
950 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
class MyWindow(QMainWindow):
clicked_times = 0
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()
def window():
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec())
window()