from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
"""
Info:
- PyQt5: cross platform gui framework (runs on Win,Mac,Linux,iOS,Android)
- Install: pip install pyqt5
"""
app = QApplication(sys.argv) # create pyqt app
win = QMainWindow() # create a window for pyqt app
win.setGeometry(500,200,500,300) # set position and windows size of win: x0,y0,width,height
win.setWindowTitle("Title of my awesome app!") # sets a title
# add label
label1 = QtWidgets.QLabel(win) # add a label to the window win
label1.move(20,20)
label1.setObjectName("label1")
label1.setText("Label 1")
# add button
button1 = QtWidgets.QPushButton(win)
button1.setGeometry(200,100,80,80)
button1.setObjectName("button1")
button1.setText("Button 1")
button1.clicked.connect(lambda: button1_clicked(button1)) # even: calls function button1_clicked when clicking button1 and passes the button as an argument
# events
def button1_clicked(b):
print(f"Button with objectName {b.objectName()} clicked!")
win.show()
sys.exit(app.exec_()) # properly exits python program when closing pyqt app