2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
2018-09-28 18:57:37 +00:00
|
|
|
if sys.version_info[0] >= 3:
|
2018-09-27 20:24:09 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-28 18:57:37 +00:00
|
|
|
else:
|
|
|
|
import PySimpleGUI27 as sg
|
2018-09-12 20:46:35 +00:00
|
|
|
"""
|
|
|
|
Demo of how to combine elements into your own custom element
|
|
|
|
"""
|
|
|
|
|
|
|
|
sg.SetOptions(element_padding=(0,0))
|
2018-09-12 22:31:39 +00:00
|
|
|
# sg.ChangeLookAndFeel('Dark')
|
2018-09-12 20:46:35 +00:00
|
|
|
# --- Define our "Big-Button-Spinner" compound element. Has 2 buttons and an input field --- #
|
2018-09-24 22:01:00 +00:00
|
|
|
NewSpinner = [sg.ReadButton('-', size=(2,1), font='Any 12'),
|
2018-09-12 22:31:39 +00:00
|
|
|
sg.In('0', size=(2,1), font='Any 14', justification='r', key='spin'),
|
2018-09-24 22:01:00 +00:00
|
|
|
sg.ReadButton('+', size=(2,1), font='Any 12')]
|
2018-09-12 20:46:35 +00:00
|
|
|
# --- Define Window --- #
|
|
|
|
layout = [
|
|
|
|
[sg.Text('Spinner simulation')],
|
|
|
|
NewSpinner,
|
|
|
|
[sg.T('')],
|
|
|
|
[sg.Ok()]
|
|
|
|
]
|
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
window = sg.Window('Spinner simulation').Layout(layout)
|
2018-09-12 20:46:35 +00:00
|
|
|
|
|
|
|
# --- Event Loop --- #
|
|
|
|
counter = 0
|
|
|
|
while True:
|
2018-10-15 20:07:23 +00:00
|
|
|
event, values = window.Read()
|
2018-09-12 20:46:35 +00:00
|
|
|
|
2018-10-15 20:07:23 +00:00
|
|
|
if event == 'Ok' or event is None: # be nice to your user, always have an exit from your form
|
2018-09-12 20:46:35 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
# --- do spinner stuff --- #
|
2018-10-15 20:07:23 +00:00
|
|
|
counter += 1 if event == '+' else -1 if event == '-' else 0
|
2018-09-24 22:01:00 +00:00
|
|
|
window.FindElement('spin').Update(counter)
|