本文整理匯總了Python中Tkinter.DoubleVar方法的典型用法代碼示例。如果您正苦於以下問題:Python Tkinter.DoubleVar方法的具體用法?Python Tkinter.DoubleVar怎麽用?Python Tkinter.DoubleVar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tkinter
的用法示例。
在下文中一共展示了Tkinter.DoubleVar方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _make_slider
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def _make_slider(self, parent, rowidx, label, inival, maxval, res=0.5):
# Create shared variable and set initial value.
tkvar = tk.DoubleVar()
tkvar.set(inival)
# Set a callback for whenever tkvar is changed.
# (The 'command' callback on the SpinBox only applies to the buttons.)
tkvar.trace('w', self._update_callback)
# Create the Label, SpinBox, and Scale objects.
label = tk.Label(parent, text=label)
spbox = tk.Spinbox(parent,
textvariable=tkvar,
from_=0, to=maxval, increment=res)
slide = tk.Scale(parent,
orient=tk.HORIZONTAL,
showvalue=0,
variable=tkvar,
from_=0, to=maxval, resolution=res)
label.grid(row=rowidx, column=0)
spbox.grid(row=rowidx, column=1)
slide.grid(row=rowidx, column=2)
return tkvar
# Find the largest output size that fits within the given bounds and
# matches the aspect ratio of the original source image.
示例2: define_variables
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def define_variables(self):
self.solver_name = tk.StringVar(self.master)
self.function = tk.StringVar(self.master)
self.popsize = tk.IntVar(self.master)
self.max_iter = tk.IntVar(self.master)
self.interval = tk.IntVar(self.master)
self.mcmc_stepsize_x1 = tk.DoubleVar(self.master)
self.mcmc_stepsize_x2 = tk.DoubleVar(self.master)
self.hmc_stepsize = tk.DoubleVar(self.master)
self.log_mcmc_stepsize_x1 = tk.DoubleVar(self.master)
self.log_mcmc_stepsize_x2 = tk.DoubleVar(self.master)
self.log_hmc_stepsize = tk.DoubleVar(self.master)
self.n_leap = tk.IntVar(self.master)
self.w = tk.DoubleVar(self.master)
self.c1 = tk.DoubleVar(self.master)
self.c2 = tk.DoubleVar(self.master)
self.gamma = tk.DoubleVar(self.master)
self.CR = tk.DoubleVar(self.master)
self.F = tk.DoubleVar(self.master)
self.strategy = tk.StringVar(self.master)
self.sigma = tk.DoubleVar(self.master)
self.mu_perc = tk.DoubleVar(self.master)
self.seed = tk.IntVar(self.master)
self.fix_seed = tk.BooleanVar(self.master)
self.constrain = tk.BooleanVar(self.master)
self.sync = tk.BooleanVar(self.master)
示例3: test_widget_destroy
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_widget_destroy(self):
# automatically created variable
x = ttk.LabeledScale()
var = x._variable._name
x.destroy()
self.assertRaises(Tkinter.TclError, x.tk.globalgetvar, var)
# manually created variable
myvar = Tkinter.DoubleVar()
name = myvar._name
x = ttk.LabeledScale(variable=myvar)
x.destroy()
self.assertEqual(x.tk.globalgetvar(name), myvar.get())
del myvar
self.assertRaises(Tkinter.TclError, x.tk.globalgetvar, name)
# checking that the tracing callback is properly removed
myvar = Tkinter.IntVar()
# LabeledScale will start tracing myvar
x = ttk.LabeledScale(variable=myvar)
x.destroy()
# Unless the tracing callback was removed, creating a new
# LabeledScale with the same var will cause an error now. This
# happens because the variable will be set to (possibly) a new
# value which causes the tracing callback to be called and then
# it tries calling instance attributes not yet defined.
ttk.LabeledScale(variable=myvar)
if hasattr(sys, 'last_type'):
self.assertFalse(sys.last_type == Tkinter.TclError)
示例4: test_set
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_set(self):
# set restricts the max/min values according to the current range
max = self.scale['to']
new_max = max + 10
self.scale.set(new_max)
self.assertEqual(self.scale.get(), max)
min = self.scale['from']
self.scale.set(min - 1)
self.assertEqual(self.scale.get(), min)
# changing directly the variable doesn't impose this limitation tho
var = Tkinter.DoubleVar()
self.scale['variable'] = var
var.set(max + 5)
self.assertEqual(self.scale.get(), var.get())
self.assertEqual(self.scale.get(), max + 5)
del var
# the same happens with the value option
self.scale['value'] = max + 10
self.assertEqual(self.scale.get(), max + 10)
self.assertEqual(self.scale.get(), self.scale['value'])
# nevertheless, note that the max/min values we can get specifying
# x, y coords are the ones according to the current range
self.assertEqual(self.scale.get(0, 0), min)
self.assertEqual(self.scale.get(self.scale.winfo_width(), 0), max)
self.assertRaises(Tkinter.TclError, self.scale.set, None)
示例5: test_variable
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_variable(self):
widget = self.create()
var = tkinter.DoubleVar(self.root)
self.checkVariableParam(widget, 'variable', var)
示例6: test_widget_destroy
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_widget_destroy(self):
# automatically created variable
x = ttk.LabeledScale(self.root)
var = x._variable._name
x.destroy()
self.assertRaises(tkinter.TclError, x.tk.globalgetvar, var)
# manually created variable
myvar = tkinter.DoubleVar(self.root)
name = myvar._name
x = ttk.LabeledScale(self.root, variable=myvar)
x.destroy()
if self.wantobjects:
self.assertEqual(x.tk.globalgetvar(name), myvar.get())
else:
self.assertEqual(float(x.tk.globalgetvar(name)), myvar.get())
del myvar
self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name)
# checking that the tracing callback is properly removed
myvar = tkinter.IntVar(self.root)
# LabeledScale will start tracing myvar
x = ttk.LabeledScale(self.root, variable=myvar)
x.destroy()
# Unless the tracing callback was removed, creating a new
# LabeledScale with the same var will cause an error now. This
# happens because the variable will be set to (possibly) a new
# value which causes the tracing callback to be called and then
# it tries calling instance attributes not yet defined.
ttk.LabeledScale(self.root, variable=myvar)
if hasattr(sys, 'last_type'):
self.assertNotEqual(sys.last_type, tkinter.TclError)
示例7: test_set
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_set(self):
if self.wantobjects:
conv = lambda x: x
else:
conv = float
# set restricts the max/min values according to the current range
max = conv(self.scale['to'])
new_max = max + 10
self.scale.set(new_max)
self.assertEqual(conv(self.scale.get()), max)
min = conv(self.scale['from'])
self.scale.set(min - 1)
self.assertEqual(conv(self.scale.get()), min)
# changing directly the variable doesn't impose this limitation tho
var = tkinter.DoubleVar(self.root)
self.scale['variable'] = var
var.set(max + 5)
self.assertEqual(conv(self.scale.get()), var.get())
self.assertEqual(conv(self.scale.get()), max + 5)
del var
# the same happens with the value option
self.scale['value'] = max + 10
self.assertEqual(conv(self.scale.get()), max + 10)
self.assertEqual(conv(self.scale.get()), conv(self.scale['value']))
# nevertheless, note that the max/min values we can get specifying
# x, y coords are the ones according to the current range
self.assertEqual(conv(self.scale.get(0, 0)), min)
self.assertEqual(conv(self.scale.get(self.scale.winfo_width(), 0)), max)
self.assertRaises(tkinter.TclError, self.scale.set, None)
示例8: test_listvariable
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_listvariable(self):
widget = self.create()
var = tkinter.DoubleVar(self.root)
self.checkVariableParam(widget, 'listvariable', var)
示例9: test_get
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_get(self):
v = DoubleVar(self.root, 1.23, "name")
self.assertAlmostEqual(1.23, v.get())
self.root.globalsetvar("name", "3.45")
self.assertAlmostEqual(3.45, v.get())
示例10: test_get_from_int
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_get_from_int(self):
v = DoubleVar(self.root, 1.23, "name")
self.assertAlmostEqual(1.23, v.get())
self.root.globalsetvar("name", "3.45")
self.assertAlmostEqual(3.45, v.get())
self.root.globalsetvar("name", "456")
self.assertAlmostEqual(456, v.get())
示例11: test_invalid_value
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_invalid_value(self):
v = DoubleVar(self.root, name="name")
self.root.globalsetvar("name", "value")
with self.assertRaises(ValueError):
v.get()
示例12: __init__
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def __init__(self, parent):
tk.LabelFrame.__init__(self, parent)
self.af_on = tk.IntVar(value=0)
self.af_on_cb = tk.Checkbutton(self, text="AF Threshold", variable=self.af_on)
self.af_on_cb.grid(row=0, column=0, padx=3, columnspan=2, sticky=tk.EW)
self.af_var = tk.DoubleVar()
self.af_gt_lt = tk.IntVar(value=1)
self.af_lt_radio_button = tk.Radiobutton(self, text="<", variable=self.af_gt_lt, value=1)
self.af_lt_radio_button.grid(row=1, column=0, sticky=tk.EW)
self.af_gt_radio_button = tk.Radiobutton(self, text=">", variable=self.af_gt_lt, value=2)
self.af_gt_radio_button.grid(row=1, column=1, sticky=tk.EW)
self.af_scale = tk.Scale(self, variable=self.af_var, from_=float(0), to=float(1), resolution=float(0.01),
orient=tk.HORIZONTAL)
self.af_scale.grid(row=2, column=0, padx=3, sticky=tk.EW, columnspan=2)
示例13: set_tk_var
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def set_tk_var():
global method
method = StringVar()
method.set(read_config("Config", "Method", "str"))
global server
server = StringVar()
server.set(read_config("Config", "Server", "str"))
global shelltype
shelltype = StringVar()
shelltype.set(read_config("Config", "ShellType", "str"))
global parameter
parameter = StringVar()
parameter.set(read_config("Config", "Parameter", "str"))
global thread_num
thread_num = IntVar()
thread_num.set(read_config("Config", "ThreadNumber", "int"))
global req_delay
req_delay = DoubleVar()
req_delay.set(read_config("Config", "RequestDelay", "float"))
global time_out
time_out = DoubleVar()
time_out.set(read_config("Config", "RequestTimeout", "float"))
global random_ua
random_ua = BooleanVar()
random_ua.set(read_config("Config", "RandomUserAgent", "boolean"))
global con_close
con_close = BooleanVar()
con_close.set(read_config("Config", "ConnectionClose", "boolean"))
global keep_alive
keep_alive = BooleanVar()
keep_alive.set(read_config("Config", "KeepAlive0", "boolean"))
global custom_hdr
custom_hdr = BooleanVar()
custom_hdr.set(read_config("Config", "CustomRequestHeader", "boolean"))
global custom_hdr_data
custom_hdr_data = StringVar()
custom_hdr_data.set(read_config("Config", "CustomRequestHeaderData", "str"))
示例14: test_initialization
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_initialization(self):
# master passing
x = ttk.LabeledScale()
self.assertEqual(x.master, Tkinter._default_root)
x.destroy()
master = Tkinter.Frame()
x = ttk.LabeledScale(master)
self.assertEqual(x.master, master)
x.destroy()
# variable initialization/passing
passed_expected = ((2.5, 2), ('0', 0), (0, 0), (10, 10),
(-1, -1), (sys.maxint + 1, sys.maxint + 1))
for pair in passed_expected:
x = ttk.LabeledScale(from_=pair[0])
self.assertEqual(x.value, pair[1])
x.destroy()
x = ttk.LabeledScale(from_='2.5')
self.assertRaises(ValueError, x._variable.get)
x.destroy()
x = ttk.LabeledScale(from_=None)
self.assertRaises(ValueError, x._variable.get)
x.destroy()
# variable should have its default value set to the from_ value
myvar = Tkinter.DoubleVar(value=20)
x = ttk.LabeledScale(variable=myvar)
self.assertEqual(x.value, 0)
x.destroy()
# check that it is really using a DoubleVar
x = ttk.LabeledScale(variable=myvar, from_=0.5)
self.assertEqual(x.value, 0.5)
self.assertEqual(x._variable._name, myvar._name)
x.destroy()
# widget positionment
def check_positions(scale, scale_pos, label, label_pos):
self.assertEqual(scale.pack_info()['side'], scale_pos)
self.assertEqual(label.place_info()['anchor'], label_pos)
x = ttk.LabeledScale(compound='top')
check_positions(x.scale, 'bottom', x.label, 'n')
x.destroy()
x = ttk.LabeledScale(compound='bottom')
check_positions(x.scale, 'top', x.label, 's')
x.destroy()
x = ttk.LabeledScale(compound='unknown') # invert default positions
check_positions(x.scale, 'top', x.label, 's')
x.destroy()
x = ttk.LabeledScale() # take default positions
check_positions(x.scale, 'bottom', x.label, 'n')
x.destroy()
# extra, and invalid, kwargs
self.assertRaises(Tkinter.TclError, ttk.LabeledScale, a='b')
示例15: test_initialization
# 需要導入模塊: import Tkinter [as 別名]
# 或者: from Tkinter import DoubleVar [as 別名]
def test_initialization(self):
# master passing
master = tkinter.Frame(self.root)
x = ttk.LabeledScale(master)
self.assertEqual(x.master, master)
x.destroy()
# variable initialization/passing
passed_expected = (('0', 0), (0, 0), (10, 10),
(-1, -1), (sys.maxint + 1, sys.maxint + 1))
if self.wantobjects:
passed_expected += ((2.5, 2),)
for pair in passed_expected:
x = ttk.LabeledScale(self.root, from_=pair[0])
self.assertEqual(x.value, pair[1])
x.destroy()
x = ttk.LabeledScale(self.root, from_='2.5')
self.assertRaises(ValueError, x._variable.get)
x.destroy()
x = ttk.LabeledScale(self.root, from_=None)
self.assertRaises(ValueError, x._variable.get)
x.destroy()
# variable should have its default value set to the from_ value
myvar = tkinter.DoubleVar(self.root, value=20)
x = ttk.LabeledScale(self.root, variable=myvar)
self.assertEqual(x.value, 0)
x.destroy()
# check that it is really using a DoubleVar
x = ttk.LabeledScale(self.root, variable=myvar, from_=0.5)
self.assertEqual(x.value, 0.5)
self.assertEqual(x._variable._name, myvar._name)
x.destroy()
# widget positionment
def check_positions(scale, scale_pos, label, label_pos):
self.assertEqual(scale.pack_info()['side'], scale_pos)
self.assertEqual(label.place_info()['anchor'], label_pos)
x = ttk.LabeledScale(self.root, compound='top')
check_positions(x.scale, 'bottom', x.label, 'n')
x.destroy()
x = ttk.LabeledScale(self.root, compound='bottom')
check_positions(x.scale, 'top', x.label, 's')
x.destroy()
# invert default positions
x = ttk.LabeledScale(self.root, compound='unknown')
check_positions(x.scale, 'top', x.label, 's')
x.destroy()
x = ttk.LabeledScale(self.root) # take default positions
check_positions(x.scale, 'bottom', x.label, 'n')
x.destroy()
# extra, and invalid, kwargs
self.assertRaises(tkinter.TclError, ttk.LabeledScale, master, a='b')