This is a submission for the Hacktoberfest Weekend Challenge: Build for a Friend
What I Built
A friend of mine sometimes has trouble concentrating on their studies, so I made them a simple Pomodoro Timer using Python.
Demo
Copy the code to a file named main.py. Feel free to use a venv. After you have done that, run the two commands below. You only have to install the PyQt6 package once.
pip install PyQt6
python main.py
Code
import sys
from PyQt6.QtCore import QSize, QTimer
from PyQt6.QtWidgets import QApplication, QHBoxLayout, QLCDNumber, QMainWindow, QPushButton, QVBoxLayout, QWidget
# Window setup
app = QApplication(sys.argv)
window = QMainWindow()
window.setWindowTitle("Pomodoro Timer")
window.setFixedSize(QSize(420, 220))
layout = QVBoxLayout()
central_widget = QWidget()
central_widget.setLayout(layout)
window.setCentralWidget(central_widget)
# LCD
lcd = QLCDNumber()
lcd.setDigitCount(8)
lcd.setFixedSize(QSize(400, 150))
lcd.display("00:45:00")
lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Filled)
layout.addWidget(lcd)
# Buttons
buttons = QWidget()
button_layout = QHBoxLayout()
toggle_button = QPushButton("Start/Stop")
reset_button = QPushButton("Reset")
button_layout.addWidget(toggle_button)
button_layout.addWidget(reset_button)
buttons.setLayout(button_layout)
layout.addWidget(buttons)
# Timer logic and connections
time_remaining = 45 * 60
filled = True
def update_time():
global time_remaining, filled
if time_remaining > 0:
time_remaining = time_remaining - 1
seconds = time_remaining
(hours, seconds) = divmod(seconds, 3600)
(minutes, seconds) = divmod(seconds, 60)
lcd.display(f"{hours:02.0f}:{minutes:02.0f}:{seconds:02.0f}")
else:
filled = not filled
lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Filled if filled else QLCDNumber.SegmentStyle.Outline)
def reset_timer():
global time_remaining
update_timer.stop()
time_remaining = 45 * 60 + 1
filled = True
lcd.setSegmentStyle(QLCDNumber.SegmentStyle.Filled)
update_time()
update_timer = QTimer()
update_timer.timeout.connect(update_time)
toggle_button.pressed.connect(lambda: update_timer.stop() if update_timer.isActive() else update_timer.start(1000))
reset_button.pressed.connect(reset_timer)
# Run the app
window.show()
app.exec()
How I Built It
By hand. No AI was used. 100% Human made.
Why Does Open Innovation Matter?
Open source libraries are what makes these applications possible. Better yet, the language used to create the application, Python, is open source itself. These libraries, language features and transparency would not be possible with closed source.
The world can, however, go without 'open' AI tools. I would like to inspire people to get out there and actually build the relevant skills to achieve their goals. AI does not replace skill.
My Agent Session
No AI was used for this submission. 100% Human made.
Top comments (0)