Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30a12bc

Browse files
Stop Watch Implementation
1. Persistant_Timer_Dialog.py : The popup window size modified. 2. Stop_Watch.py : Implemented a stop watch version using the Py GUI options available.
1 parent a943dba commit 30a12bc

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

‎Persistant_Timer_Dialog.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[sg.Text(size=(16,2),key='text')],
77
[sg.Button('Pause',key='Pause'),sg.Button('Resume',key='Resume'), sg.Exit(key='Exit')]]
88

9-
window = sg.Window('Timer', layout)
9+
window = sg.Window('Timer', layout, size=(300, 120), modal=True)
1010

1111
while True:
1212
event, values = window.read(timeout=10)

‎Stop_Watch.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import PySimpleGUI as sg
2+
import time
3+
4+
# Change the default look and feel / theme of the window.
5+
sg.ChangeLookAndFeel('Black')
6+
sg.SetOptions(element_padding=(2, 2))
7+
8+
layout = [[sg.Text('')],
9+
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')],
10+
[sg.ReadButton('Pause', key='button', button_color=('white', '#001480')),
11+
sg.ReadButton('Reset', button_color=('white', '#007339'), key='Reset'),
12+
sg.Exit(button_color=('white', 'firebrick4'), key='Exit')]]
13+
14+
window = sg.Window('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout)
15+
16+
current_time = 0
17+
stop_watched_paused = False
18+
start_time = int(round(time.time() * 100))
19+
20+
# start the window event loop
21+
while (True):
22+
23+
# For more details on non-blobking window events and the usage of 'timeout' parameter
24+
# read @ https://github.com/PySimpleGUI/PySimpleGUI/issues/520
25+
# Read with a timeout is a very good thing for your GUIs to use in a read non-blocking situation,
26+
# if you can use them. If your device can wait for a little while, then use this kind of read.
27+
# The longer you're able to add to the timeout value, the less CPU time you'll be taking).
28+
# window.read(timeout=10) : This program will quickly test for user input, then deal with the hardware.
29+
# Then it'll sleep for 10ms, while your gui is non-responsive, then it'll check in with your GUI again.
30+
if not stop_watched_paused:
31+
event, values = window.read(timeout=10)
32+
current_time = int(round(time.time() * 100)) - start_time
33+
else:
34+
event, values = window.Read()
35+
36+
# this is to flex between the Pause/Resume the stop watch. We work with the button text to trigger
37+
# the required concerned event.
38+
if event == 'button':
39+
event = window.FindElement(event).GetText()
40+
41+
# Close window if exit is pressed.
42+
if event == 'Exit':
43+
break
44+
45+
# Reset the stop watch timer.
46+
if event == 'Reset':
47+
start_time = int(round(time.time() * 100))
48+
current_time = 0
49+
50+
# Pause the stop watch timer.
51+
if event == 'Pause':
52+
stop_watched_paused = True
53+
paused_time = int(round(time.time() * 100))
54+
window.FindElement('button').update(text='Resume')
55+
56+
# Resume the stop watch timer event.
57+
if event == 'Resume':
58+
stop_watched_paused = False
59+
start_time = start_time + int(round(time.time() * 100)) - paused_time
60+
window.FindElement('button').update(text='Pause')
61+
62+
# Read and update window
63+
#current_time = int(round(time.time() * 100)) - start_time
64+
65+
# Display timer in window
66+
window.FindElement('text').Update('{:02d}:{:02d}.{:02d}'.format((current_time // 100) // 60,
67+
(current_time // 100) % 60,
68+
current_time % 100))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /