Slider change_submits feature. Update method for Slider, updated Font Sizer demo
This commit is contained in:
parent
b7c095d9c0
commit
3793ff81c2
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
# Testing async form, see if can have a spinner
|
# Testing async form, see if can have a slider
|
||||||
# that adjusts the size of text displayed
|
# that adjusts the size of text displayed
|
||||||
|
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
@ -8,8 +8,10 @@ form = sg.FlexForm("Font size selector")
|
||||||
|
|
||||||
fontSize = 12
|
fontSize = 12
|
||||||
sampleText = sg.Text("Aa", size=(2, 1), font="Helvetica " + str(fontSize))
|
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')
|
||||||
|
spin = sg.Spin([sz for sz in range(4,72)], font=('Helvetica 20'), initial_value=fontSize, change_submits=True, key='spin')
|
||||||
layout = [
|
layout = [
|
||||||
[sampleText, sg.Spin([sz for sz in range(4,72)], font=('Helvetica 20'), initial_value=fontSize, change_submits=True, key='spin')],
|
[sampleText, spin, slider],
|
||||||
[sg.OK(), sg.Cancel()]
|
[sg.OK(), sg.Cancel()]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -19,10 +21,15 @@ while True:
|
||||||
button, values= form.Read()
|
button, values= form.Read()
|
||||||
if button is None:
|
if button is None:
|
||||||
break
|
break
|
||||||
sz = int(values['spin'])
|
sz_spin = int(values['spin'])
|
||||||
|
sz_slider = int(values['slider'])
|
||||||
|
sz = sz_spin if sz_spin != fontSize else sz_slider
|
||||||
if sz != fontSize:
|
if sz != fontSize:
|
||||||
|
print(sampleText.Font, sampleText.Size)
|
||||||
fontSize = sz
|
fontSize = sz
|
||||||
font = "Helvetica " + str(fontSize)
|
font = "Helvetica " + str(fontSize)
|
||||||
sampleText.Update(font=font)
|
sampleText.Update(font=font)
|
||||||
|
slider.Update(sz)
|
||||||
|
spin.Update(sz)
|
||||||
|
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
|
|
@ -442,6 +442,9 @@ class Spin(Element):
|
||||||
super().__init__(ELEM_TYPE_INPUT_SPIN, scale, size, auto_size_text, font=font,background_color=bg, text_color=fg, key=key, pad=pad)
|
super().__init__(ELEM_TYPE_INPUT_SPIN, scale, size, auto_size_text, font=font,background_color=bg, text_color=fg, key=key, pad=pad)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def Update(self, new_value):
|
||||||
|
self.TKStringVar.set(new_value)
|
||||||
|
|
||||||
def SpinChangedHandler(self, event):
|
def SpinChangedHandler(self, event):
|
||||||
# first, get the results table built
|
# first, get the results table built
|
||||||
# modify the Results table in the parent FlexForm object
|
# modify the Results table in the parent FlexForm object
|
||||||
|
@ -888,18 +891,23 @@ class Frame(Element):
|
||||||
# Slider #
|
# Slider #
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
class Slider(Element):
|
class Slider(Element):
|
||||||
def __init__(self, range=(None,None), default_value=None, resolution=None, orientation=None, border_width=None, relief=None, scale=(None, None), size=(None, None), font=None, background_color=None, text_color=None, key=None, pad=None):
|
def __init__(self, range=(None,None), default_value=None, resolution=None, orientation=None, border_width=None, relief=None, change_submits=False, scale=(None, None), size=(None, None), font=None, background_color=None, text_color=None, key=None, pad=None):
|
||||||
'''
|
'''
|
||||||
Slider Element
|
Slider
|
||||||
:param range:
|
:param range:
|
||||||
:param default_value:
|
:param default_value:
|
||||||
|
:param resolution:
|
||||||
:param orientation:
|
:param orientation:
|
||||||
:param border_width:
|
:param border_width:
|
||||||
:param relief:
|
:param relief:
|
||||||
:param scale: Adds multiplier to size (w,h)
|
:param change_submits:
|
||||||
:param size: Size of field in characters
|
:param scale:
|
||||||
:param background_color: Color for Element. Text or RGB Hex
|
:param size:
|
||||||
:param font:
|
:param font:
|
||||||
|
:param background_color:
|
||||||
|
:param text_color:
|
||||||
|
:param key:
|
||||||
|
:param pad:
|
||||||
'''
|
'''
|
||||||
self.TKScale = None
|
self.TKScale = None
|
||||||
self.Range = (1,10) if range == (None, None) else range
|
self.Range = (1,10) if range == (None, None) else range
|
||||||
|
@ -908,6 +916,7 @@ class Slider(Element):
|
||||||
self.BorderWidth = border_width if border_width else DEFAULT_SLIDER_BORDER_WIDTH
|
self.BorderWidth = border_width if border_width else DEFAULT_SLIDER_BORDER_WIDTH
|
||||||
self.Relief = relief if relief else DEFAULT_SLIDER_RELIEF
|
self.Relief = relief if relief else DEFAULT_SLIDER_RELIEF
|
||||||
self.Resolution = 1 if resolution is None else resolution
|
self.Resolution = 1 if resolution is None else resolution
|
||||||
|
self.ChangeSubmits = change_submits
|
||||||
|
|
||||||
super().__init__(ELEM_TYPE_INPUT_SLIDER, scale=scale, size=size, font=font, background_color=background_color, text_color=text_color, key=key, pad=pad)
|
super().__init__(ELEM_TYPE_INPUT_SLIDER, scale=scale, size=size, font=font, background_color=background_color, text_color=text_color, key=key, pad=pad)
|
||||||
return
|
return
|
||||||
|
@ -917,6 +926,12 @@ class Slider(Element):
|
||||||
if range != (None, None):
|
if range != (None, None):
|
||||||
self.TKScale.config(from_ = range[0], to_ = range[1])
|
self.TKScale.config(from_ = range[0], to_ = range[1])
|
||||||
|
|
||||||
|
def SliderChangedHandler(self, event):
|
||||||
|
# first, get the results table built
|
||||||
|
# modify the Results table in the parent FlexForm object
|
||||||
|
self.ParentForm.LastButtonClicked = ''
|
||||||
|
self.ParentForm.FormRemainedOpen = True
|
||||||
|
self.ParentForm.TKroot.quit() # kick the users out of the mainloop
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
super().__del__()
|
super().__del__()
|
||||||
|
@ -1871,7 +1886,9 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
else:
|
else:
|
||||||
range_from = element.Range[0]
|
range_from = element.Range[0]
|
||||||
range_to = element.Range[1]
|
range_to = element.Range[1]
|
||||||
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 = 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)
|
# tktext_label.configure(anchor=tk.NW, image=photo)
|
||||||
tkscale.config(highlightthickness=0)
|
tkscale.config(highlightthickness=0)
|
||||||
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
|
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
|
||||||
|
|
Loading…
Reference in New Issue