Python Tkinter.DoubleVar() Examples
The following are 20
code examples of Tkinter.DoubleVar().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Tkinter
, or try the search function
.
Example #1
Source File: fisheye.py From DualFisheye with MIT License | 7 votes |
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.
Example #2
Source File: test_variables.py From oss-ftp with MIT License | 5 votes |
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())
Example #3
Source File: test_widgets.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test_listvariable(self): widget = self.create() var = tkinter.DoubleVar(self.root) self.checkVariableParam(widget, 'listvariable', var)
Example #4
Source File: test_widgets.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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)
Example #5
Source File: test_extensions.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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)
Example #6
Source File: gui.py From stochopy with MIT License | 5 votes |
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)
Example #7
Source File: cheetah_config_support.py From cheetah-gui with GNU General Public License v3.0 | 5 votes |
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"))
Example #8
Source File: gui_widgets.py From SVPV with MIT License | 5 votes |
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)
Example #9
Source File: test_variables.py From oss-ftp with MIT License | 5 votes |
def test_invalid_value(self): v = DoubleVar(self.root, name="name") self.root.globalsetvar("name", "value") with self.assertRaises(ValueError): v.get()
Example #10
Source File: test_variables.py From oss-ftp with MIT License | 5 votes |
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())
Example #11
Source File: test_widgets.py From oss-ftp with MIT License | 5 votes |
def test_listvariable(self): widget = self.create() var = tkinter.DoubleVar(self.root) self.checkVariableParam(widget, 'listvariable', var)
Example #12
Source File: test_widgets.py From oss-ftp with MIT License | 5 votes |
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)
Example #13
Source File: test_extensions.py From oss-ftp with MIT License | 5 votes |
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)
Example #14
Source File: widget_tests.py From oss-ftp with MIT License | 5 votes |
def test_variable(self): widget = self.create() var = tkinter.DoubleVar(self.root) self.checkVariableParam(widget, 'variable', var)
Example #15
Source File: test_widgets.py From BinderFilter with MIT License | 5 votes |
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)
Example #16
Source File: test_extensions.py From BinderFilter with MIT License | 5 votes |
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)
Example #17
Source File: test_extensions.py From oss-ftp with MIT License | 4 votes |
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')
Example #18
Source File: test_extensions.py From BinderFilter with MIT License | 4 votes |
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')
Example #19
Source File: test_extensions.py From PokemonGo-DesktopMap with MIT License | 4 votes |
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')
Example #20
Source File: fisheye.py From DualFisheye with MIT License | 4 votes |
def _make_slider(self, parent, rowidx, label, inival): # Set limits and resolution. lim = 1.0 res = 0.001 # Create shared variable. 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_=-lim, to=lim, increment=res) slide = tk.Scale(parent, orient=tk.HORIZONTAL, showvalue=0, variable=tkvar, from_=-lim, to=lim, resolution=res) label.grid(row=rowidx, column=0, sticky='W') spbox.grid(row=rowidx, column=1) slide.grid(row=rowidx, column=2) return tkvar # Thin wrapper for update_preview(), used to strip Tkinter arguments.