Font sizer - fixed exit detection. Change Submits for Slider - don't setup unless change_submits flag is set

This commit is contained in:
MikeTheWatchGuy 2018-09-01 10:51:19 -04:00
parent c4364a2109
commit 421e96e800
2 changed files with 38 additions and 6 deletions

View File

@ -8,7 +8,7 @@ form = sg.FlexForm("Font size selector")
fontSize = 12
sampleText = sg.Text("Aa", size=(2, 1), font="Helvetica " + str(fontSize))
slider = sg.Slider(range=(6,50), orientation='h', size=(10,20), change_submits=True, key='slider')
slider = sg.Slider(range=(6,50), orientation='h', size=(10,20), change_submits=False, key='slider')
spin = sg.Spin([sz for sz in range(4,72)], font=('Helvetica 20'), initial_value=fontSize, change_submits=True, key='spin')
layout = [
[sampleText, spin, slider],
@ -19,7 +19,7 @@ sz = fontSize
form.Layout(layout)
while True:
button, values= form.Read()
if button is None:
if button in (None, 'OK', 'Cancel'):
break
sz_spin = int(values['spin'])
sz_slider = int(values['slider'])

View File

@ -937,6 +937,37 @@ class Slider(Element):
super().__del__()
# ---------------------------------------------------------------------- #
# TkScrollableFrame (Used by Column (SOON) #
# ---------------------------------------------------------------------- #
# TODO NOT YET WORKING! DO NOT USE. Will be used to make scrollable columns
class TkScrollableFrame(tk.Frame):
def __init__(self, master, **kwargs):
tk.Frame.__init__(self, master, **kwargs)
# create a canvas object and a vertical scrollbar for scrolling it
self.vscrollbar = tk.Scrollbar(self, orient=tk.VERTICAL)
self.vscrollbar.pack(side='right', fill="y", expand="false")
self.canvas = tk.Canvas(self, yscrollcommand=self.vscrollbar.set)
self.canvas.pack(side="left")
self.vscrollbar.config(command=self.canvas.yview)
# reset the view
self.canvas.xview_moveto(0)
self.canvas.yview_moveto(0)
# create a frame inside the canvas which will be scrolled with it
# self.interior = tk.Frame(self.canvas, **kwargs)
# self.canvas.create_window(0, 0, window=self.interior, anchor="nw")
# self.bind('<Configure>', self.set_scrollregion)
def set_scrollregion(self, event=None):
""" Set the scroll region on the canvas"""
self.canvas.configure(scrollregion=self.canvas.bbox('all'))
# ---------------------------------------------------------------------- #
# Column #
# ---------------------------------------------------------------------- #
@ -1576,6 +1607,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
# ------------------------- COLUMN element ------------------------- #
if element_type == ELEM_TYPE_COLUMN:
col_frame = tk.Frame(tk_row_frame)
# col_frame = TkScrollableFrame(tk_row_frame) # do not use yet! not working
PackFormIntoFrame(element, col_frame, toplevel_form)
col_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
if element.BackgroundColor != COLOR_SYSTEM_DEFAULT and element.BackgroundColor is not None:
@ -1886,10 +1918,10 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
else:
range_from = element.Range[0]
range_to = element.Range[1]
if element.ChangeSubmits:
tkscale = tk.Scale(tk_row_frame, orient=element.Orientation, variable=element.TKIntVar, from_=range_from, to_=range_to, resolution = element.Resolution, length=slider_length, width=slider_width , bd=element.BorderWidth, relief=element.Relief, font=font, command=element.SliderChangedHandler)
# if element.ChangeSubmits:
# element.tkscale.bind('<Change>', element.SliderChangedHandler)
# tktext_label.configure(anchor=tk.NW, image=photo)
else:
tkscale = tk.Scale(tk_row_frame, orient=element.Orientation, variable=element.TKIntVar, from_=range_from, to_=range_to, resolution = element.Resolution, length=slider_length, width=slider_width , bd=element.BorderWidth, relief=element.Relief, font=font)
tkscale.config(highlightthickness=0)
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
tkscale.configure(background=element.BackgroundColor)