Uploaded August 2024 | Updated September 2026, 1 week ago
#python #pythontutorial #pythoncourse
00:00:00 intro
00:00:16 pip install PyQt5
00:00:37 imports
00:01:56 class Stopwatch(QWidget)
00:02:28 if __name__
00:03:54 START HERE
00:05:57 method declarations
00:06:55 initUI()
00:09:40 setStyleSheet()
00:12:28 signals and slots
00:13:33 methods definitions
# Python PyQt5 Stopwatch
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QLabel,
QPushButton, QVBoxLayout, QHBoxLayout)
from PyQt5.QtCore import QTimer, QTime, Qt
class Stopwatch(QWidget):
def __init__(self):
super().__init__()
self.time = QTime(0, 0, 0, 0)
self.time_label = QLabel("00:00:00.00", self)
self.start_button = QPushButton("Start", self)
self.stop_button = QPushButton("Stop", self)
self.reset_button = QPushButton("Reset", self)
self.timer = QTimer(self)
self.initUI()
def initUI(self):
self.setWindowTitle("Stopwatch")
vbox = QVBoxLayout()
vbox.addWidget(self.time_label)
self.setLayout(vbox)
self.time_label.setAlignment(Qt.AlignCenter)
hbox = QHBoxLayout()
hbox.addWidget(self.start_button)
hbox.addWidget(self.stop_button)
hbox.addWidget(self.reset_button)
vbox.addLayout(hbox)
self.setStyleSheet("""
QPushButton, QLabel{
padding: 20px;
font-weight: bold;
font-family: calibri;
}
QPushButton{
font-size: 50px;
}
QLabel{
font-size: 120px;
background-color: hsl(200, 100%, 85%);
border-radius: 20px;
}
""")
self.start_button.clicked.connect(self.start)
self.stop_button.clicked.connect(self.stop)
self.reset_button.clicked.connect(self.reset)
self.timer.timeout.connect(self.update_display)
def start(self):
self.timer.start(10)
def stop(self):
self.timer.stop()
def reset(self):
self.timer.stop()
self.time = QTime(0, 0, 0, 0)
self.time_label.setText(self.format_time(self.time))
def format_time(self, time):
hours = time.hour()
minutes = time.minute()
seconds = time.second()
milliseconds = time.msec() // 10
return f"{hours:02}:{minutes:02}:{seconds:02}.{milliseconds:02}"
def update_display(self):
self.time = self.time.addMSecs(10)
self.time_label.setText(self.format_time(self.time))
if ___name___ == "__main__":
app = QApplication(sys.argv)
stopwatch = Stopwatch()
stopwatch.show()
sys.exit(app.exec_())
#python #pythontutorial #pythoncourse
00:00:00 intro
00:00:16 pip install PyQt5
00:00:37 imports
00:01:56 class Stopwatch(QWidget)
00:02:28 if __name__
00:03:54 START HERE
00:05:57 method declarations
00:06:55 initUI()
00:09:40 setStyleSheet()
00:12:28 signals and slots
00:13:33 methods definitions
# Python PyQt5 Stopwatch
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QLabel,
QPushButton, QVBoxLayout, QHBoxLayout)
from PyQt5.QtCore import QTimer, QTime, Qt
class Stopwatch(QWidget):
def __init__(self):
super().__init__()
self.time = QTime(0, 0, 0, 0)
self.time_label = QLabel("00:00:00.00", self)
self.start_button = QPushButton("Start", self)
self.stop_button = QPushButton("Stop", self)
self.reset_button = QPushButton("Reset", self)
self.timer = QTimer(self)
self.initUI()
def initUI(self):
self.setWindowTitle("Stopwatch")
vbox = QVBoxLayout()
vbox.addWidget(self.time_label)
self.setLayout(vbox)
self.time_label.setAlignment(Qt.AlignCenter)
hbox = QHBoxLayout()
hbox.addWidget(self.start_button)
hbox.addWidget(self.stop_button)
hbox.addWidget(self.reset_button)
vbox.addLayout(hbox)
self.setStyleSheet("""
QPushButton, QLabel{
padding: 20px;
font-weight: bold;
font-family: calibri;
}
QPushButton{
font-size: 50px;
}
QLabel{
font-size: 120px;
background-color: hsl(200, 100%, 85%);
border-radius: 20px;
}
""")
self.start_button.clicked.connect(self.start)
self.stop_button.clicked.connect(self.stop)
self.reset_button.clicked.connect(self.reset)
self.timer.timeout.connect(self.update_display)
def start(self):
self.timer.start(10)
def stop(self):
self.timer.stop()
def reset(self):
self.timer.stop()
self.time = QTime(0, 0, 0, 0)
self.time_label.setText(self.format_time(self.time))
def format_time(self, time):
hours = time.hour()
minutes = time.minute()
seconds = time.second()
milliseconds = time.msec() // 10
return f"{hours:02}:{minutes:02}:{seconds:02}.{milliseconds:02}"
def update_display(self):
self.time = self.time.addMSecs(10)
self.time_label.setText(self.format_time(self.time))
if ___name___ == "__main__":
app = QApplication(sys.argv)
stopwatch = Stopwatch()
stopwatch.show()
sys.exit(app.exec_())






![Learn C programming variables easy! ❎
#coding #programming #cprogramming
00:00:00 int
00:04:06 float
00:07:35 double
00:09:26 char
00:11:34 char[]
00:14:37 bool
00:18:55 extra details
// variable = A reusable container for a value.
// Behaves as if it were the value it contains.
// int = whole numbers (4 bytes in modern systems)
// float = single-precision decimal number (4 bytes)
// double = double-precision decimal number (8 bytes)
// char = single character (1 byte)
// char[] = array of characters (size varies)
// bool = true or false (1 byte) Learn C programming variables easy! ❎](https://i.ytimg.com/vi/WrFEtUzVcnw/mqdefault.jpg)
![Learn runtime polymorphism in 5 minutes! 🤷♂️
#java #javatutorial #javacourse
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Runtime polymorphism = When the method that gets executed is decided
// at runtime based on the actual type of the object.
Scanner scanner = new Scanner(System.in);
Animal animal;
System.out.print(Would you like a dog or a cat? (1 = dog, 2 = cat): );
int choice = scanner.nextInt();
if(choice 1){
animal = new Dog();
animal.speak();
}
else if(choice 2){
animal = new Cat();
animal.speak();
}
}
} Learn runtime polymorphism in 5 minutes! 🤷♂️](https://i.ytimg.com/vi/YDKHfqzaF30/mqdefault.jpg)


