本文整理汇总了Python中tkinter.ttk.Scale方法的典型用法代码示例。如果您正苦于以下问题:Python ttk.Scale方法的具体用法?Python ttk.Scale怎么用?Python ttk.Scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk
的用法示例。
在下文中一共展示了ttk.Scale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _scale
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def _scale(self, from_, to, resolution, variable, position, command = None,
kwargs = {}):
if command is None:
command = lambda s: variable.set(round(float(s), 3))
scale = ttk.Scale(self.frame1.sliders, from_ = from_, to = to, variable = variable,
orient = "horizontal", length = 20, command = command,
takefocus = False, **kwargs)
if position == 1:
scale.place(relwidth = 0.35, relx = 0, x = 0, y = 25, anchor = "nw")
elif position == 2:
scale.place(relwidth = 0.35, relx = 0, x = 0, y = 70, anchor = "nw")
elif position == 3:
scale.place(relwidth = 0.35, relx = 0.5, x = 0, y = 25, anchor = "nw")
elif position == 4:
scale.place(relwidth = 0.35, relx = 0.5, x = 0, y = 70, anchor = "nw")
return scale
示例2: checkParam
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def checkParam(self, widget, name, value, *, expected=_sentinel,
conv=False, eq=None):
widget[name] = value
if expected is _sentinel:
expected = value
if conv:
expected = conv(expected)
if self._stringify or not self.wantobjects:
if isinstance(expected, tuple):
expected = tkinter._join(expected)
else:
expected = str(expected)
if eq is None:
eq = tcl_obj_eq
self.assertEqual2(widget[name], expected, eq=eq)
self.assertEqual2(widget.cget(name), expected, eq=eq)
# XXX
if not isinstance(widget, Scale):
t = widget.configure(name)
self.assertEqual(len(t), 5)
self.assertEqual2(t[4], expected, eq=eq)
示例3: config_cleaner
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def config_cleaner(widget):
""" Some options don't like to be copied, so this returns a cleaned
configuration from a widget
We use config() instead of configure() because some items (ttk Scale) do
not populate configure()"""
new_config = dict()
for key in widget.config():
if key == "class":
continue
val = widget.cget(key)
# Some keys default to "" but tkinter doesn't like to set config to this value
# so skip them to use default value.
if key in ("anchor", "justify", "compound") and val == "":
continue
val = str(val) if isinstance(val, Tcl_Obj) else val
# Return correct command from master command dict
val = _RECREATE_OBJECTS["commands"][val] if key == "command" and val != "" else val
new_config[key] = val
return new_config
示例4: test_keys
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def test_keys(self):
widget = self.create()
keys = widget.keys()
# XXX
if not isinstance(widget, Scale):
self.assertEqual(sorted(keys), sorted(widget.configure()))
for k in keys:
widget[k]
# Test if OPTIONS contains all keys
if test.support.verbose:
aliases = {
'bd': 'borderwidth',
'bg': 'background',
'fg': 'foreground',
'invcmd': 'invalidcommand',
'vcmd': 'validatecommand',
}
keys = set(keys)
expected = set(self.OPTIONS)
for k in sorted(keys - expected):
if not (k in aliases and
aliases[k] in keys and
aliases[k] in expected):
print('%s.OPTIONS doesn\'t contain "%s"' %
(self.__class__.__name__, k))
示例5: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def __init__(self, master):
ttk.Label(master, text = "PROGRESS CONTROL").pack()
# Inderterminant Progressbar
ttk.Label(master, text = 'Inderterminant Progress').pack()
self.prgrsbr_indtr = ttk.Progressbar(master, orient = tk.HORIZONTAL, length = 300, mode = 'indeterminate')
self.prgrsbr_indtr.pack()
self.checkpbi = tk.StringVar()
self.checkpbi.set("Start")
# Button
self.btn1 = ttk.Button(master, text = "{} Inderterminant Progress Bar".format(self.checkpbi.get()), command = self.btn1cmd)
self.btn1.pack()
# Derterminant progress
ttk.Label(master, text = 'Derterminant Progress').pack()
self.prgrsbr_dtr = ttk.Progressbar(master, orient=tk.HORIZONTAL, length = 300, mode = 'determinate')
self.prgrsbr_dtr.pack()
self.prgrsbr_dtr.config(maximum = 10.0, value = 2.0) # notice both these properties have float values
# Button
ttk.Button(master, text = 'Reset Progress Bar to zero', command = self.resetProgressBarVal).pack()
# Button
ttk.Button(master, text = 'Increase Progress Bar by 2', command = self.shift2ProgressBarVal).pack()
# create double variable
self.prgrsBrVal = tk.DoubleVar()
self.prgrsbr_dtr.config(variable = self.prgrsBrVal) # set variable property of progressbar to look at DoubleVar()
# Scale widget
self.scalebar = ttk.Scale(master, orient = tk.HORIZONTAL, length = 400, variable=self.prgrsBrVal, from_ = 0.0, to= 10.0)
self.scalebar.pack()
# Label to display current value of scalebar
ttk.Label(master, text = "Current value of Progress Bar is as below:").pack()
self.scalebar_label = ttk.Label(master, textvariable = self.prgrsBrVal)
self.scalebar_label.pack()
示例6: _update_slider_length_horizontal
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def _update_slider_length_horizontal(self):
"""
Measure the length of the slider and update the value of self._sliderlength.
self.scale.identify(x, y) is used to find the first and last pixels of
the slider. Indeed, self.scale.identify(x, y) returns the element
of the ttk.Scale to which the pixel (x, y) belongs. So, the length of
the slider is determined by scanning horizontally the pixels of the scale.
"""
if not self.scale.identify(2, 2):
# if self.scale.identify(2, 2) is an empty string it means that the scale
# is not displayed yet so we cannot measure the length of the slider,
# so wait for the scale to be properly displayed.
# binding to <Map> event does not work, it can still be to soon to
# get any result from identify
self.after(10, self._update_slider_length_horizontal)
else:
w = self.scale.winfo_width()
i = 0
# find the first pixel of the slider
while i < w and 'slider' not in self.scale.identify(i, 2):
# increment i until the pixel (i, 2) belongs to the slider
i += 1
j = i
# find the last pixel of the slider
while j < w and 'slider' in self.scale.identify(j, 2):
# increment j until the pixel (2, j) no longer belongs to the slider
j += 1
if j == i:
# the length of the slider was not determined properly,
# so the value of the sliderlength from the style is used
self._sliderlength = self.style.lookup(self._style_name, 'sliderlength', default=30)
else:
# update ticks and label placement
self._sliderlength = j - i
self._update_display()
示例7: _update_slider_length_vertical
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def _update_slider_length_vertical(self):
"""
Measure the length of the slider and update the value of self._sliderlength.
self.scale.identify(x, y) is used to find the first and last pixels of
the slider. Indeed, self.scale.identify(x, y) returns the element
of the ttk.Scale to which the pixel (x, y) belongs. So, the length of
the slider is determined by scanning vertically the pixels of the scale.
"""
if not self.scale.identify(2, 2):
# if self.scale.identify(2, 2) is an empty string it means that the scale
# is not displayed yet so we cannot measure the length of the slider,
# so wait for the scale to be properly displayed.
# binding to <Map> event does not work, it can still be to soon to
# get any result from identify
self.after(10, self._update_slider_length_vertical)
else:
h = self.scale.winfo_height()
i = 0
# find the first pixel of the slider
while i < h and 'slider' not in self.scale.identify(2, i):
# increment i until the pixel (2, i) belongs to the slider
i += 1
j = i
# find the last pixel of the slider
while j < h and 'slider' in self.scale.identify(2, j):
# increment j until the pixel (2, j) no longer belongs to the slider
j += 1
if j == i:
# the length of the slider was not determined properly,
# so the value of the sliderlength from the style is used
self._sliderlength = self.style.lookup(self._style_name, 'sliderlength', default=30)
else:
self._sliderlength = j - i
# update ticks and label placement
self._update_display()
示例8: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def __init__(self, master=None, scalewidth=50, entrywidth=5, from_=0, to=50,
orient=tk.HORIZONTAL, compound=tk.RIGHT, entryscalepad=0, **kwargs):
"""
Create a ScaleEntry.
:param master: master widget
:type master: widget
:param scalewidth: width of the Scale in pixels
:type scalewidth: int
:param entrywidth: width of the Entry in characters
:type entrywidth: int
:param from\_: start value of the scale
:type from\_: int
:param to: end value of the scale
:type to: int
:param orient: scale orientation. Supports :obj:`tk.HORIZONTAL` and :obj:`tk.VERTICAL`
:type orient: str
:param compound: side the Entry must be on. Supports :obj:`tk.LEFT`,
:obj:`tk.RIGHT`, :obj:`tk.TOP` and :obj:`tk.BOTTOM`
:type compound: str
:param entryscalepad: space between the entry and the scale
:type entryscalepad: int
:param kwargs: keyword arguments passed on to the :class:`ttk.Frame` initializer
"""
ttk.Frame.__init__(self, master, **kwargs)
if compound is not tk.RIGHT and compound is not tk.LEFT and compound is not tk.TOP and \
compound is not tk.BOTTOM:
raise ValueError("Invalid value for compound passed {0}".format(compound))
self.__compound = compound
if not isinstance(entryscalepad, int):
raise TypeError("entryscalepad not of int type")
self.__entryscalepad = entryscalepad
self._variable = self.LimitedIntVar(from_, to)
self._scale = ttk.Scale(self, from_=from_, to=to, length=scalewidth,
orient=orient, command=self._on_scale,
variable=self._variable)
# Note that the textvariable keyword argument is not used to pass the LimitedIntVar
self._entry = ttk.Entry(self, width=entrywidth)
self._entry.insert(0, str(from_))
self._entry.bind("<KeyRelease>", self._on_entry)
self._grid_widgets()
示例9: _on_entry
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def _on_entry(self, event):
"""
Callback for the Entry widget, sets the Scale variable to the appropriate value.
:param event: Tkinter event
"""
contents = self._entry.get()
if contents == "":
return
try:
value = self._variable.set(int(contents))
except ValueError:
value = None
if not value:
self._on_scale(None)
示例10: _on_scale
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def _on_scale(self, event):
"""
Callback for the Scale widget, inserts an int value into the Entry.
:param event: Tkinter event
"""
self._entry.delete(0, tk.END)
self._entry.insert(0, str(self._variable.get()))
示例11: config_scale
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def config_scale(self, cnf={}, **kwargs):
"""Configure resources of the Scale widget."""
self._scale.config(cnf, **kwargs)
# Update self._variable limits in case the ones of the scale have changed
self._variable.configure(high=self._scale['to'],
low=self._scale['from'])
if 'orient' in cnf or 'orient' in kwargs:
self._grid_widgets()
示例12: create
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def create(self, **kwargs):
return ttk.Scale(self.root, **kwargs)
示例13: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def __init__(self, master, title):
self.title = title
super().__init__(master, text=title, padding=4)
self.player = None # will be connected later
self.volumeVar = tk.DoubleVar(value=100)
self.volumefilter = VolumeFilter()
ttk.Label(self, text="title / artist / album").pack()
self.titleLabel = ttk.Label(self, relief=tk.GROOVE, width=22, anchor=tk.W)
self.titleLabel.pack()
self.artistLabel = ttk.Label(self, relief=tk.GROOVE, width=22, anchor=tk.W)
self.artistLabel.pack()
self.albumlabel = ttk.Label(self, relief=tk.GROOVE, width=22, anchor=tk.W)
self.albumlabel.pack()
f = ttk.Frame(self)
ttk.Label(f, text="time left: ").pack(side=tk.LEFT)
self.timeleftLabel = ttk.Label(f, relief=tk.GROOVE, anchor=tk.CENTER)
self.timeleftLabel.pack(side=tk.RIGHT, fill=tk.X, expand=True)
f.pack(fill=tk.X)
f = ttk.Frame(self)
ttk.Label(f, text="V: ").pack(side=tk.LEFT)
scale = ttk.Scale(f, from_=0, to=150, length=120, variable=self.volumeVar, command=self.on_volumechange)
scale.bind("<Double-1>", self.on_dblclick_vol)
scale.pack(side=tk.LEFT)
self.volumeLabel = ttk.Label(f, text="???%")
self.volumeLabel.pack(side=tk.RIGHT)
f.pack(fill=tk.X)
ttk.Button(self, text="Skip", command=lambda s=self: s.player.skip(s)).pack(pady=4)
self.volume = 100
self.stateLabel = tk.Label(self, text="STATE", relief=tk.SUNKEN, border=1)
self.stateLabel.pack()
self._track = None
self._time = None
self._stream = None
self._state = self.state_needtrack
self.state = self.state_needtrack
self.xfade_state = self.state_xfade_nofade
self.xfade_started = None
self.xfade_start_volume = None
self.playback_started = None
self.track_duration = None
示例14: create_control_panel
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def create_control_panel(self):
frame=Tkinter.LabelFrame(self.root)
frame.pack(expand='yes',fill='x',side='top')
add_fileicon=Tkinter.PhotoImage(file="../Icons/add_file.gif")
add_directoryicon=Tkinter.PhotoImage(file="../Icons/add_directory.gif")
exiticon=Tkinter.PhotoImage(file="../Icons/exit.gif")
playicon=Tkinter.PhotoImage(file="../Icons/play.gif")
pauseicon=Tkinter.PhotoImage(file="../Icons/pause.gif")
stopicon=Tkinter.PhotoImage(file="../Icons/stop.gif")
rewindicon=Tkinter.PhotoImage(file="../Icons/rewind.gif")
fast_forwardicon=Tkinter.PhotoImage(file="../Icons/fast_forward.gif")
previous_trackicon=Tkinter.PhotoImage(file="../Icons/previous_track.gif")
next_trackicon=Tkinter.PhotoImage(file="../Icons/next_track.gif")
self.muteicon=Tkinter.PhotoImage(file="../Icons/mute.gif")
self.unmuteicon=Tkinter.PhotoImage(file="../Icons/unmute.gif")
delete_selectedicon=Tkinter.PhotoImage(file="../Icons/delete_selected.gif")
list_file=[
(playicon,'self.play'),
(pauseicon,'self.pause'),
(stopicon,'self.stop'),
(previous_trackicon,'self.previous'),
(rewindicon,'self.rewind'),
(fast_forwardicon,'self.fast'),
(next_trackicon,'self.Next'),]
for i,j in list_file:
storeobj=ttk.Button(frame, image=i,command=eval(j))
storeobj.pack(side='left')
storeobj.image=i
self.volume_label=Tkinter.Button(frame,image=self.unmuteicon)
self.volume_label.image=self.unmuteicon
volume=ttk.Scale(frame,from_=Volume_lowest_value, to=Volume_highest_value ,variable=self.var, command=self.update_volume)
volume.pack(side='right', padx=10, )
self.volume_label.pack(side='right')
return
示例15: add_option_smoothing
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Scale [as 别名]
def add_option_smoothing(self):
""" Add refresh button to refresh graph immediately """
logger.debug("Adding Smoothing Slider")
tk_var = get_config().tk_vars["smoothgraph"]
min_max = (0, 0.99)
hlp = "Set the smoothing amount. 0 is no smoothing, 0.99 is maximum smoothing."
ctl_frame = ttk.Frame(self.optsframe)
ctl_frame.pack(padx=2, side=tk.RIGHT)
lbl = ttk.Label(ctl_frame, text="Smoothing Amount:", anchor=tk.W)
lbl.pack(pady=5, side=tk.LEFT, anchor=tk.N, expand=True)
tbox = ttk.Entry(ctl_frame, width=6, textvariable=tk_var, justify=tk.RIGHT)
tbox.pack(padx=(0, 5), side=tk.RIGHT)
ctl = ttk.Scale(
ctl_frame,
variable=tk_var,
command=lambda val, var=tk_var, dt=float, rn=2, mm=(0, 0.99):
set_slider_rounding(val, var, dt, rn, mm))
ctl["from_"] = min_max[0]
ctl["to"] = min_max[1]
ctl.pack(padx=5, pady=5, fill=tk.X, expand=True)
for item in (tbox, ctl):
Tooltip(item,
text=hlp,
wraplength=200)
logger.debug("Added Smoothing Slider")