-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-1.py
76 lines (59 loc) · 2.29 KB
/
app-1.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QVBoxLayout, QWidget
# Subclass QMainWindow to customize your application's main window
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Andrea")
self.setFixedSize(400, 200)
central_widget = QWidget(self)
central_widget.setMinimumSize(400, 200)
central_widget.setStyleSheet("background-color: lightblue")
self.setCentralWidget(central_widget)
# Create a layout for the central widget
layout = QVBoxLayout()
layout.setAlignment(Qt.AlignCenter)
button = QPushButton("Press Me!")
# add clickCount attribute to the button
button.clickCount = 0
#make the button background color light green hover color dark green
button.setStyleSheet("""
QPushButton {
background-color: lightgreen;
border: 1px solid darkgreen;
color: black;
padding: 10px;
}
QPushButton:hover {
background-color: darkgreen;
color: white;
}""")
label = QLabel("Hello World")
#make the label background color light pink add a padding of 10px
label.setStyleSheet("""
QLabel {
background-color: pink;
padding: 10px;
border: 1px solid red;
}
QLabel:hover {
background-color: red;
color: white;
}""")
central_widget.setMouseTracking(True)
layout.addWidget(button)
layout.addWidget(label)
# Set the central widget of the Window.
central_widget.setLayout(layout)
# add the label below the button
# self.addDockWidget(Qt.BottomDockWidgetArea, label)
# when button is clicked, set the label text to "Button Clicked n times"
button.clicked.connect(lambda: self.buttonClicked(button, label))
def buttonClicked(self, button, label):
button.clickCount += 1
label.setText(f"Label Button Clicked {button.clickCount} times")
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()