|
4 | 4 | # form that doen't block |
5 | 5 | # good for applications with an loop that polls hardware |
6 | 6 | def Timer(): |
7 | | - sg.ChangeLookAndFeel('TealMono') |
| 7 | + sg.ChangeLookAndFeel('Dark') |
8 | 8 | # Make a form, but don't use context manager |
9 | | - form = sg.FlexForm('Running Timer', auto_size_text=True) |
| 9 | + form = sg.FlexForm('Running Timer', grab_anywhere=False, no_titlebar=True, auto_size_buttons=False) |
10 | 10 | # Create a text element that will be updated with status information on the GUI itself |
11 | 11 | # Create the rows |
12 | 12 | form_rows = [[sg.Text('Stopwatch')], |
13 | 13 | [sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')], |
14 | | - [sg.ReadFormButton('Pause/Resume'), sg.ReadFormButton('Reset')]] |
| 14 | + [sg.ReadFormButton('Pause'), sg.ReadFormButton('Reset'), sg.Exit()]] |
15 | 15 | # Layout the rows of the form and perform a read. Indicate the form is non-blocking! |
16 | | - form.LayoutAndRead(form_rows, non_blocking=True) |
17 | | - |
18 | | - # |
19 | | - # Some place later in your code... |
20 | | - # You need to perform a ReadNonBlocking on your form every now and then or |
21 | | - # else it won't refresh. |
| 16 | + form.Layout(form_rows) |
22 | 17 | # |
23 | 18 | # your program's main loop |
24 | 19 | i = 0 |
25 | 20 | paused = False |
26 | 21 | while (True): |
27 | 22 | # This is the code that reads and updates your window |
28 | | - form.FindElement('text').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100)) |
29 | 23 | button, values = form.ReadNonBlocking() |
| 24 | + form.FindElement('text').Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100)) |
30 | 25 |
|
31 | | - if values is None: |
| 26 | + if values is None or button == 'Exit': |
32 | 27 | break |
33 | 28 |
|
34 | 29 | if button is 'Reset': |
35 | 30 | i=0 |
36 | | - elif button is 'Pause/Resume': |
| 31 | + elif button is 'Pause': |
37 | 32 | paused = not paused |
38 | 33 |
|
39 | 34 | if not paused: |
|
0 commit comments