-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyQt6_Traffic_Light.py
49 lines (39 loc) · 2.31 KB
/
PyQt6_Traffic_Light.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
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication
from PyQt6.QtCore import QTimer
import sys
class MainWIdget(QWidget):
def __init__(self):
super().__init__()
self.setFixedSize(180, 500)
self.layout = QVBoxLayout()
self.buttonRed = QPushButton()
self.buttonYellow = QPushButton()
self.buttonGreen = QPushButton()
self.layout.addWidget(self.buttonRed)
self.layout.addWidget(self.buttonYellow)
self.layout.addWidget(self.buttonGreen)
self.setStyleSheet("background-color: black;")
self.setLayout(self.layout)
self.timer = QTimer(self)
self.setRed()
def setRed(self):
self.buttonRed.setStyleSheet("background-color: red; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.buttonYellow.setStyleSheet("background-color: black; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.buttonGreen.setStyleSheet("background-color: black; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.timer.singleShot(2000, self.setRedYellow)
def setRedYellow(self):
self.buttonYellow.setStyleSheet("background-color: yellow; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.timer.singleShot(2000, self.setGreen)
def setGreen(self):
self.buttonRed.setStyleSheet("background-color: black; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.buttonYellow.setStyleSheet("background-color: black; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.buttonGreen.setStyleSheet("background-color: green; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.timer.singleShot(2000, self.setYellow)
def setYellow(self):
self.buttonYellow.setStyleSheet("background-color: yellow; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.buttonGreen.setStyleSheet("background-color: black; border: 1px solid black; border-radius: 75px; width: 150px; height: 150px;")
self.timer.singleShot(2000, self.setRed)
app = QApplication(sys.argv)
window = MainWIdget()
window.show()
sys.exit(app.exec())