commit
c14ba594e7
|
@ -866,9 +866,10 @@ class Button(Element):
|
|||
_my_windows.Decrement()
|
||||
return
|
||||
|
||||
def Update(self, new_text, button_color=(None, None)):
|
||||
def Update(self, new_text=None, button_color=(None, None)):
|
||||
try:
|
||||
self.TKButton.configure(text=new_text)
|
||||
if new_text is not None:
|
||||
self.TKButton.configure(text=new_text)
|
||||
if button_color != (None, None):
|
||||
self.TKButton.config(foreground=button_color[0], background=button_color[1])
|
||||
except:
|
||||
|
@ -1618,6 +1619,7 @@ def BuildResults(form, initialize_only, top_level_form):
|
|||
form.ReturnValuesDictionary = {}
|
||||
form.ReturnValuesList = []
|
||||
BuildResultsForSubform(form, initialize_only, top_level_form)
|
||||
top_level_form.LastButtonClicked = None
|
||||
return form.ReturnValues
|
||||
|
||||
def BuildResultsForSubform(form, initialize_only, top_level_form):
|
||||
|
@ -1801,7 +1803,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
|||
PackFormIntoFrame(element, col_frame.TKFrame, toplevel_form)
|
||||
col_frame.TKFrame.update()
|
||||
if element.Size == (None, None):
|
||||
col_frame.canvas.config(width=col_frame.TKFrame.winfo_reqwidth(),height=col_frame.TKFrame.winfo_reqheight())
|
||||
col_frame.canvas.config(width=col_frame.TKFrame.winfo_reqwidth()/2,height=col_frame.TKFrame.winfo_reqheight()/2)
|
||||
else:
|
||||
col_frame.canvas.config(width=element.Size[0],height=element.Size[1])
|
||||
|
||||
|
@ -1971,11 +1973,13 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
|||
# ------------------------- OPTION MENU (Like ComboBox but different) element ------------------------- #
|
||||
elif element_type == ELEM_TYPE_INPUT_OPTION_MENU:
|
||||
max_line_len = max([len(str(l)) for l in element.Values])
|
||||
if auto_size_text is False: width=element_size[0]
|
||||
else: width = max_line_len
|
||||
element.TKStringVar = tk.StringVar()
|
||||
default = element.DefaultValue if element.DefaultValue else element.Values[0]
|
||||
element.TKStringVar.set(default)
|
||||
element.TKOptionMenu = tk.OptionMenu(tk_row_frame, element.TKStringVar ,*element.Values )
|
||||
element.TKOptionMenu.config(highlightthickness=0, font=font)
|
||||
element.TKOptionMenu = tk.OptionMenu(tk_row_frame, element.TKStringVar ,*element.Values)
|
||||
element.TKOptionMenu.config(highlightthickness=0, font=font, width=width )
|
||||
element.TKOptionMenu.config(borderwidth=border_depth)
|
||||
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
|
||||
element.TKOptionMenu.configure(background=element.BackgroundColor)
|
||||
|
|
|
@ -843,3 +843,66 @@ While there is no official support for "Tables" (e.g. there is no Table Element)
|
|||
layout.append([sg.T(f'{i}{j}', size=(4,1), background_color='white', pad=(1,1)) for j in range(10)])
|
||||
|
||||
sg.FlexForm('Table').LayoutAndRead(layout)
|
||||
|
||||
## Tight Layout
|
||||
|
||||
Saw this example layout written in tkinter and liked it so much I duplicated the interface. It's "tight", clean, and has a nice dark look and feel.
|
||||
|
||||
This Recipe also contains code that implements the button interactions so that you'll have a template to build from.
|
||||
|
||||
In other GUI frameworks this program would be most likely "event driven" with callback functions being used to communicate button events. The "event loop" would be handled by the GUI engine. If code already existed that used a call-back mechanism, the loop in the example code below could simply call these callback functions directly based on the button text it receives in the form.Read call.
|
||||
|
||||

|
||||
|
||||
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('Dark')
|
||||
sg.SetOptions(element_padding=(0, 0))
|
||||
|
||||
StartButton = sg.ReadFormButton('Start', button_color=('white', 'black'))
|
||||
StopButton = sg.ReadFormButton('Stop', button_color=('gray34', 'black'))
|
||||
ResetButton = sg.ReadFormButton('Reset', button_color=('gray', 'firebrick3'))
|
||||
SubmitButton = sg.ReadFormButton('Submit', button_color=('gray34', 'springgreen4'))
|
||||
|
||||
layout = [
|
||||
[sg.T('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User 2'), size=(20, 1)), sg.T('0', size=(8, 1))],
|
||||
[sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)),
|
||||
sg.T('1', size=(8, 1))],
|
||||
[sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black')],
|
||||
[StartButton, StopButton, ResetButton, SubmitButton]
|
||||
]
|
||||
|
||||
form = sg.FlexForm("Time Tracker", default_element_size=(12, 1), text_justification='r', auto_size_text=False,
|
||||
auto_size_buttons=False,
|
||||
default_button_element_size=(12, 1))
|
||||
form.Layout(layout)
|
||||
recording = have_data = False
|
||||
while True:
|
||||
button, values = form.Read()
|
||||
if button is None:
|
||||
exit(69)
|
||||
if button is 'Start':
|
||||
StartButton.Update(button_color=('gray34', 'black'))
|
||||
StopButton.Update(button_color=('white', 'black'))
|
||||
ResetButton.Update(button_color=('white', 'firebrick3'))
|
||||
recording = True
|
||||
elif button is 'Stop' and recording:
|
||||
StopButton.Update(button_color=('gray34', 'black'))
|
||||
StartButton.Update(button_color=('white', 'black'))
|
||||
SubmitButton.Update(button_color=('white', 'springgreen4'))
|
||||
recording = False
|
||||
have_data = True
|
||||
elif button is 'Reset':
|
||||
StopButton.Update(button_color=('gray34', 'black'))
|
||||
StartButton.Update(button_color=('white', 'black'))
|
||||
SubmitButton.Update(button_color=('gray34', 'springgreen4'))
|
||||
ResetButton.Update(button_color=('gray34', 'firebrick3'))
|
||||
recording = False
|
||||
have_data = False
|
||||
elif button is 'Submit' and have_data:
|
||||
StopButton.Update(button_color=('gray34', 'black'))
|
||||
StartButton.Update(button_color=('white', 'black'))
|
||||
SubmitButton.Update(button_color=('gray34', 'springgreen4'))
|
||||
ResetButton.Update(button_color=('gray34', 'firebrick3'))
|
||||
recording = False
|
||||
|
|
Loading…
Reference in New Issue