2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
2018-09-12 20:46:35 +00:00
|
|
|
"""
|
|
|
|
Demo of how to combine elements into your own custom element
|
|
|
|
"""
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.set_options(element_padding=(0, 0))
|
2020-01-03 00:07:59 +00:00
|
|
|
# --- Define the Compound Element. Has 2 buttons and an input field --- #
|
|
|
|
NewSpinner = [sg.Input('0', size=(3, 1), font='Any 12', justification='r', key='-SPIN-'),
|
|
|
|
sg.Column([[sg.Button('▲', size=(1, 1), font='Any 7', border_width=0, button_color=(sg.theme_text_color(), sg.theme_background_color()), key='-UP-')],
|
|
|
|
[sg.Button('▼', size=(1, 1), font='Any 7', border_width=0, button_color=(sg.theme_text_color(), sg.theme_background_color()), key='-DOWN-')]])]
|
2018-09-12 20:46:35 +00:00
|
|
|
# --- Define Window --- #
|
2020-01-03 00:07:59 +00:00
|
|
|
layout = [[sg.Text('Spinner simulation')],
|
|
|
|
NewSpinner,
|
|
|
|
[sg.Text('')],
|
|
|
|
[sg.Ok()]]
|
2018-09-12 20:46:35 +00:00
|
|
|
|
2020-01-03 00:07:59 +00:00
|
|
|
window = sg.Window('Spinner simulation', layout, use_default_focus=False)
|
2018-09-12 20:46:35 +00:00
|
|
|
|
|
|
|
# --- Event Loop --- #
|
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2018-09-12 20:46:35 +00:00
|
|
|
|
2020-05-07 10:22:59 +00:00
|
|
|
if event == 'Ok' or event == sg.WIN_CLOSED: # be nice to your user, always have an exit from your form
|
2018-09-12 20:46:35 +00:00
|
|
|
break
|
2020-01-03 00:07:59 +00:00
|
|
|
counter = int(values['-SPIN-'])
|
2018-09-12 20:46:35 +00:00
|
|
|
# --- do spinner stuff --- #
|
2020-01-03 00:07:59 +00:00
|
|
|
counter += 1 if event == '-UP-' else -1 if event == '-DOWN-' else 0
|
|
|
|
window['-SPIN-'].update(counter)
|
2019-10-23 20:10:03 +00:00
|
|
|
window.close()
|