Python tkinter.ttk.Checkbutton() Examples
The following are 30
code examples of tkinter.ttk.Checkbutton().
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.ttk
, or try the search function
.
Example #1
Source File: annotation_gui.py From SEM with MIT License | 9 votes |
def preferences(self, event=None): preferenceTop = tkinter.Toplevel() preferenceTop.focus_set() notebook = ttk.Notebook(preferenceTop) frame1 = ttk.Frame(notebook) notebook.add(frame1, text='general') frame2 = ttk.Frame(notebook) notebook.add(frame2, text='shortcuts') c = ttk.Checkbutton(frame1, text="Match whole word when broadcasting annotation", variable=self._whole_word) c.pack() shortcuts_vars = [] shortcuts_gui = [] cur_row = 0 j = -1 frame_list = [] frame_list.append(ttk.LabelFrame(frame2, text="common shortcuts")) frame_list[-1].pack(fill="both", expand="yes") for i, shortcut in enumerate(self.shortcuts): j += 1 key, cmd, bindings = shortcut name, command = cmd shortcuts_vars.append(tkinter.StringVar(frame_list[-1], value=key)) tkinter.Label(frame_list[-1], text=name).grid(row=cur_row, column=0, sticky=tkinter.W) entry = tkinter.Entry(frame_list[-1], textvariable=shortcuts_vars[j]) entry.grid(row=cur_row, column=1) cur_row += 1 notebook.pack() # # ? menu methods #
Example #2
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 7 votes |
def set(self, value, *args, **kwargs): if type(self.variable) == tk.BooleanVar: self.variable.set(bool(value)) elif self.variable: self.variable.set(value, *args, **kwargs) elif type(self.input) in (ttk.Checkbutton, ttk.Radiobutton): if value: self.input.select() else: self.input.deselect() elif type(self.input) == tk.Text: self.input.delete('1.0', tk.END) self.input.insert('1.0', value) else: self.input.delete(0, tk.END) self.input.insert(0, value)
Example #3
Source File: ComboComponentFrame.py From Endless-Sky-Mission-Builder with GNU General Public License v3.0 | 6 votes |
def __init__(self, parent, component_name, list_combobox_data, tooltip_key): ttk.Frame.__init__(self, parent) self.columnconfigure(0, weight=1) logging.debug("\t\tBuilding \"%s\"" % component_name) label = widgets.TooltipLabel(self, tooltip_key, text=component_name) label.grid(row=0, column=0, sticky="w", padx=(5, 0)) self.listComboboxData = list_combobox_data self.is_active = BooleanVar() self.option = None self.button = ttk.Checkbutton(self, onvalue=1, offvalue=0, variable=self.is_active) self.combo = ttk.Combobox(self, state="disabled", values=self.listComboboxData, style='D.TCombobox') self.combo.bind("<<ComboboxSelected>>", self.option_selected) self.button.configure(command=partial(self._cb_value_changed, self.is_active, [self.combo])) self.button.grid(row=0, column=1, sticky="e") self.combo.grid(row=1, column=0, sticky="ew", padx=(20,0)) #end init
Example #4
Source File: toggledframe.py From ttkwidgets with GNU General Public License v3.0 | 6 votes |
def __init__(self, master=None, text="", width=20, compound=tk.LEFT, **kwargs): """ Create a ToggledFrame. :param master: master widget :type master: widget :param text: text to display next to the toggle arrow :type text: str :param width: width of the closed ToggledFrame (in characters) :type width: int :param compound: "center", "none", "top", "bottom", "right" or "left": position of the toggle arrow compared to the text :type compound: str :param kwargs: keyword arguments passed on to the :class:`ttk.Frame` initializer """ ttk.Frame.__init__(self, master, **kwargs) self._open = False self.__checkbutton_var = tk.BooleanVar() self._open_image = ImageTk.PhotoImage(Image.open(os.path.join(get_assets_directory(), "open.png"))) self._closed_image = ImageTk.PhotoImage(Image.open(os.path.join(get_assets_directory(), "closed.png"))) self._checkbutton = ttk.Checkbutton(self, style="Toolbutton", command=self.toggle, variable=self.__checkbutton_var, text=text, compound=compound, image=self._closed_image, width=width) self.interior = ttk.Frame(self, relief=tk.SUNKEN) self._grid_widgets()
Example #5
Source File: categories_checkbox_gui.py From pyDEA with MIT License | 6 votes |
def on_select_box(self, box, count): ''' This method is called when the user clicks on a Checkbutton. It updates corresponding parameters that must be changed after clicking on Checkbutton. Args: box (Label): Label that stores category name. count (int): index of the Checkbutton that distinguishes between Checkbuttons responsible for non-discretionary categories and weakly disposal categories. ''' param_name = COUNT_TO_NAME[count] category_name = box.cget('text') if self.options[category_name][count].get() == 1: value = self.params.get_parameter_value(param_name) if value: value += '; ' self.params.update_parameter(param_name, value + category_name) else: values = self.params.get_set_of_parameters(param_name) if category_name in values: values.remove(category_name) new_value = '; '.join(values) self.params.update_parameter(param_name, new_value)
Example #6
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_invoke(self): success = [] def cb_test(): success.append(1) return "cb test called" cbtn = ttk.Checkbutton(self.root, command=cb_test) # the variable automatically created by ttk.Checkbutton is actually # undefined till we invoke the Checkbutton self.assertEqual(cbtn.state(), ('alternate', )) self.assertRaises(tkinter.TclError, cbtn.tk.globalgetvar, cbtn['variable']) res = cbtn.invoke() self.assertEqual(res, "cb test called") self.assertEqual(cbtn['onvalue'], cbtn.tk.globalgetvar(cbtn['variable'])) self.assertTrue(success) cbtn['command'] = '' res = cbtn.invoke() self.assertFalse(str(res)) self.assertLessEqual(len(success), 1) self.assertEqual(cbtn['offvalue'], cbtn.tk.globalgetvar(cbtn['variable']))
Example #7
Source File: test_widgets.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_invoke(self): success = [] def cb_test(): success.append(1) return "cb test called" cbtn = ttk.Checkbutton(self.root, command=cb_test) # the variable automatically created by ttk.Checkbutton is actually # undefined till we invoke the Checkbutton self.assertEqual(cbtn.state(), ('alternate', )) self.assertRaises(tkinter.TclError, cbtn.tk.globalgetvar, cbtn['variable']) res = cbtn.invoke() self.assertEqual(res, "cb test called") self.assertEqual(cbtn['onvalue'], cbtn.tk.globalgetvar(cbtn['variable'])) self.assertTrue(success) cbtn['command'] = '' res = cbtn.invoke() self.assertFalse(str(res)) self.assertLessEqual(len(success), 1) self.assertEqual(cbtn['offvalue'], cbtn.tk.globalgetvar(cbtn['variable']))
Example #8
Source File: m6e_checkbox_and_radio_buttons.py From TkinterPractice with MIT License | 6 votes |
def button_pressed(checkbutton_observer, radiobutton_observer): print('After 2 seconds, I will toggle the Checkbutton') print('and reset the radiobutton to Peter\'s.') time.sleep(2) if checkbutton_observer.get() == '1': checkbutton_observer.set('0') else: checkbutton_observer.set('1') radiobutton_observer.set('peter') # ---------------------------------------------------------------------- # Calls main to start the ball rolling. # ----------------------------------------------------------------------
Example #9
Source File: control_helper.py From faceswap with GNU General Public License v3.0 | 6 votes |
def get_control(self): """ Set the correct control type based on the datatype or for this option """ if self.choices and self.is_radio: control = "radio" elif self.choices and self.is_multi_option: control = "multi" elif self.choices and self.choices == "colorchooser": control = "colorchooser" elif self.choices: control = ttk.Combobox elif self.dtype == bool: control = ttk.Checkbutton elif self.dtype in (int, float): control = "scale" else: control = ttk.Entry logger.debug("Setting control '%s' to %s", self.title, control) return control
Example #10
Source File: control_helper.py From faceswap with GNU General Public License v3.0 | 6 votes |
def build_one_control(self): """ Build and place the option controls """ logger.debug("Build control: '%s')", self.option.name) if self.option.control == "scale": ctl = self.slider_control() elif self.option.control in ("radio", "multi"): ctl = self._multi_option_control(self.option.control) elif self.option.control == "colorchooser": ctl = self._color_control() elif self.option.control == ttk.Checkbutton: ctl = self.control_to_checkframe() else: ctl = self.control_to_optionsframe() if self.option.control != ttk.Checkbutton: ctl.pack(padx=5, pady=5, fill=tk.X, expand=True) if self.option.helptext is not None and not self.helpset: _get_tooltip(ctl, text=self.option.helptext, wraplength=600) logger.debug("Built control: '%s'", self.option.name)
Example #11
Source File: display_analysis.py From faceswap with GNU General Public License v3.0 | 6 votes |
def opts_checkbuttons(self, frame): """ Add the options check buttons """ logger.debug("Building Check Buttons") self.add_section(frame, "Display") for item in ("raw", "trend", "avg", "smoothed", "outliers"): if item == "avg": text = "Show Rolling Average" elif item == "outliers": text = "Flatten Outliers" else: text = "Show {}".format(item.title()) var = tk.BooleanVar() if item == self.default_view: var.set(True) self.vars[item] = var ctl = ttk.Checkbutton(frame, variable=var, text=text) ctl.pack(side=tk.TOP, padx=5, pady=5, anchor=tk.W) hlp = self.set_help(item) Tooltip(ctl, text=hlp, wraplength=200) logger.debug("Built Check Buttons")
Example #12
Source File: gui.py From skan with BSD 3-Clause "New" or "Revised" License | 6 votes |
def create_parameters_frame(self, parent): parameters = ttk.Frame(master=parent, padding=STANDARD_MARGIN) parameters.grid(sticky='nsew') heading = ttk.Label(parameters, text='Analysis parameters') heading.grid(column=0, row=0, sticky='n') for i, param in enumerate(self.parameters, start=1): param_label = ttk.Label(parameters, text=param._name) param_label.grid(row=i, column=0, sticky='nsew') if type(param) == tk.BooleanVar: param_entry = ttk.Checkbutton(parameters, variable=param) elif hasattr(param, '_choices'): param_entry = ttk.OptionMenu(parameters, param, param.get(), *param._choices.keys()) else: param_entry = ttk.Entry(parameters, textvariable=param) param_entry.grid(row=i, column=1, sticky='nsew')
Example #13
Source File: AggregatedTriggerFrame.py From Endless-Sky-Mission-Builder with GNU General Public License v3.0 | 6 votes |
def populate_trigger(self, trigger): """ This method populates the GUI with a TriggerFrame widget, then stores the data from trigger inside it :param trigger: the trigger containing the data to be populated """ tf = widgets.TriggerFrame(self, "trigger", populating=True) tf.trigger = trigger state = BooleanVar() cb = ttk.Checkbutton(tf.frame, onvalue=1, offvalue=0, variable=state) cb.configure(command=partial(self._change_trigger_state, state, trigger)) cb.grid(row=0, column=3, sticky="e") if trigger.is_active: state.set(1) self._change_trigger_state(state, trigger) #end populate_trigger
Example #14
Source File: AggregatedLogFrame.py From Endless-Sky-Mission-Builder with GNU General Public License v3.0 | 6 votes |
def _add_log(self): """ Add a log to the current trigger. We can assume a specific trigger because these functions are only accessible after has opened the trigger they are adding this log to. """ logging.debug("Adding Trigger...") lf = widgets.LogFrame(self, self.trigger) widgets.TypeSelectorWindow(self, ["<type> <name> <message>", "<message>"], self._set_format_type) logging.debug("Log format type selected: %s" % lf.log.format_type) if lf.log.format_type == "cancelled": lf.cleanup() return #end if self.edit_log(self.log_frame_list[-1]) state = BooleanVar() cb = ttk.Checkbutton(lf.frame, onvalue=1, offvalue=0, variable=state) cb.configure(command=partial(self._change_log_state, state, self.log_frame_list[-1].log)) cb.grid(row=0, column=3, sticky="e") #end _add_log
Example #15
Source File: AggregatedLogFrame.py From Endless-Sky-Mission-Builder with GNU General Public License v3.0 | 6 votes |
def populate_log(self, log): """ This method populates the GUI with a LogFrame widget, then stores the data from log inside it :param log: the log containing the data to be populated """ lf = widgets.LogFrame(self, self.trigger, populating=True) lf.log = log state = BooleanVar() cb = ttk.Checkbutton(lf.frame, onvalue=1, offvalue=0, variable=state) cb.configure(command=partial(self._change_log_state, state, log)) cb.grid(row=0, column=3, sticky="e") if log.is_active: state.set(1) self._change_log_state(state, log) #end populate_log
Example #16
Source File: AggregatedTriggerConditionFrame.py From Endless-Sky-Mission-Builder with GNU General Public License v3.0 | 6 votes |
def populate_trigger_condition(self, condition): """ This method populates the GUI with a TriggerConditionFrame widget, then stores the data from condition inside it :param condition: the TriggerCondition containing the data to be populated """ tc = widgets.TriggerConditionFrame(self, self.trigger, populating=True) tc.condition = condition state = BooleanVar() cb = ttk.Checkbutton(tc.frame, onvalue=1, offvalue=0, variable=state) cb.configure(command=partial(self._change_tc_state, state, tc)) cb.grid(row=0, column=3, sticky="e") if condition.is_active: state.set(1) self._change_tc_state(state, condition) #end populate_trigger_condition
Example #17
Source File: test_widgets.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_invoke(self): success = [] def cb_test(): success.append(1) return "cb test called" cbtn = ttk.Checkbutton(self.root, command=cb_test) # the variable automatically created by ttk.Checkbutton is actually # undefined till we invoke the Checkbutton self.assertEqual(cbtn.state(), ('alternate', )) self.assertRaises(tkinter.TclError, cbtn.tk.globalgetvar, cbtn['variable']) res = cbtn.invoke() self.assertEqual(res, "cb test called") self.assertEqual(cbtn['onvalue'], cbtn.tk.globalgetvar(cbtn['variable'])) self.assertTrue(success) cbtn['command'] = '' res = cbtn.invoke() self.assertFalse(str(res)) self.assertLessEqual(len(success), 1) self.assertEqual(cbtn['offvalue'], cbtn.tk.globalgetvar(cbtn['variable']))
Example #18
Source File: user_interface.py From open-mcr with GNU General Public License v3.0 | 6 votes |
def __init__(self, parent: PackTarget, label: str, on_change: tp.Optional[tp.Callable] = None, reduce_padding_above: bool = False): self.__on_change = on_change self.__raw_value = tk.IntVar(parent, 0) internal_padding = int(XPADDING * 0.33) external_padding = XPADDING top_padding = external_padding if not reduce_padding_above else 0 pack_opts = {"side": tk.LEFT, "pady": (top_padding, external_padding)} frame = tk.Frame(parent) self.__checkbox = pack(ttk.Checkbutton(frame, text=label, command=self.__on_update, variable=self.__raw_value, padding=internal_padding, width=50), **pack_opts, padx=(external_padding, 0)) frame.pack() self.value = False
Example #19
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def set(self, value, *args, **kwargs): if type(self.variable) == tk.BooleanVar: self.variable.set(bool(value)) elif self.variable: self.variable.set(value, *args, **kwargs) elif type(self.input) in (ttk.Checkbutton, ttk.Radiobutton): if value: self.input.select() else: self.input.deselect() elif type(self.input) == tk.Text: self.input.delete('1.0', tk.END) self.input.insert('1.0', value) else: self.input.delete(0, tk.END) self.input.insert(0, value)
Example #20
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def set(self, value, *args, **kwargs): if type(self.variable) == tk.BooleanVar: self.variable.set(bool(value)) elif self.variable: self.variable.set(value, *args, **kwargs) elif type(self.input) in (ttk.Checkbutton, ttk.Radiobutton): if value: self.input.select() else: self.input.deselect() elif type(self.input) == tk.Text: self.input.delete('1.0', tk.END) self.input.insert('1.0', value) else: self.input.delete(0, tk.END) self.input.insert(0, value)
Example #21
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, parent, label='', input_class=ttk.Entry, input_var=None, input_args=None, label_args=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = input_var else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = input_var self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #22
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def set(self, value, *args, **kwargs): if type(self.variable) == tk.BooleanVar: self.variable.set(bool(value)) elif self.variable: self.variable.set(value, *args, **kwargs) elif type(self.input) in (ttk.Checkbutton, ttk.Radiobutton): if value: self.input.select() else: self.input.deselect() elif type(self.input) == tk.Text: self.input.delete('1.0', tk.END) self.input.insert('1.0', value) else: self.input.delete(0, tk.END) self.input.insert(0, value)
Example #23
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, parent, label='', input_class=None, input_var=None, input_args=None, label_args=None, field_spec=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} if field_spec: field_type = field_spec.get('type', FT.string) input_class = input_class or self.field_types.get(field_type)[0] var_type = self.field_types.get(field_type)[1] self.variable = input_var if input_var else var_type() # min, max, increment if 'min' in field_spec and 'from_' not in input_args: input_args['from_'] = field_spec.get('min') if 'max' in field_spec and 'to' not in input_args: input_args['to'] = field_spec.get('max') if 'inc' in field_spec and 'increment' not in input_args: input_args['increment'] = field_spec.get('inc') # values if 'values' in field_spec and 'values' not in input_args: input_args['values'] = field_spec.get('values') else: self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = self.variable else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = self.variable self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error, **label_args) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #24
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, parent, label='', input_class=None, input_var=None, input_args=None, label_args=None, field_spec=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} if field_spec: field_type = field_spec.get('type', FT.string) input_class = input_class or self.field_types.get(field_type)[0] var_type = self.field_types.get(field_type)[1] self.variable = input_var if input_var else var_type() # min, max, increment if 'min' in field_spec and 'from_' not in input_args: input_args['from_'] = field_spec.get('min') if 'max' in field_spec and 'to' not in input_args: input_args['to'] = field_spec.get('max') if 'inc' in field_spec and 'increment' not in input_args: input_args['increment'] = field_spec.get('inc') # values if 'values' in field_spec and 'values' not in input_args: input_args['values'] = field_spec.get('values') else: self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = self.variable else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = self.variable self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error, **label_args) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #25
Source File: toggled_frame.py From clai with MIT License | 5 votes |
def __init__(self, parent, text="", *args, **options): tk.Frame.__init__(self, parent, *args, **options) self.show = tk.IntVar() self.show.set(0) self.title_frame = ttk.Frame(self) self.title_frame.pack( fill="x", expand=True) title_label = \ tk.Label(self.title_frame, text=text, anchor="nw", justify=LEFT, fg='white', padx=15, pady=15, bg="black") title_label.pack(side="left", fill="x", expand=True) path = os.path.dirname(os.path.abspath(__file__)) self.expand_more_image = tk.PhotoImage(file=f"{path}/expand_less.gif") self.expand_less_image = tk.PhotoImage(file=f"{path}/expand_more.gif") self.toggle_button = \ ttk.Checkbutton(self.title_frame, width=2, image=self.expand_more_image, command=self.toggle, variable=self.show, style='TLabel') self.toggle_button.pack(side="left") self.sub_frame = tk.Frame(self, relief="sunken", borderwidth=1)
Example #26
Source File: control_helper.py From faceswap with GNU General Public License v3.0 | 5 votes |
def build_control(self): """ Build the correct control type for the option passed through """ logger.debug("Build config option control") if self.option.control not in (ttk.Checkbutton, "radio", "multi", "colorchooser"): self.build_control_label() self.build_one_control() logger.debug("Built option control")
Example #27
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, parent, label='', input_class=None, input_var=None, input_args=None, label_args=None, field_spec=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} if field_spec: field_type = field_spec.get('type', FT.string) input_class = input_class or self.field_types.get(field_type)[0] var_type = self.field_types.get(field_type)[1] self.variable = input_var if input_var else var_type() # min, max, increment if 'min' in field_spec and 'from_' not in input_args: input_args['from_'] = field_spec.get('min') if 'max' in field_spec and 'to' not in input_args: input_args['to'] = field_spec.get('max') if 'inc' in field_spec and 'increment' not in input_args: input_args['increment'] = field_spec.get('inc') # values if 'values' in field_spec and 'values' not in input_args: input_args['values'] = field_spec.get('values') else: self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = self.variable else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = self.variable self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #28
Source File: display_page.py From faceswap with GNU General Public License v3.0 | 5 votes |
def add_option_enable(self): """ Add checkbutton to enable/disable page """ logger.debug("Adding enable option") chkenable = ttk.Checkbutton(self.optsframe, variable=self.vars["enabled"], text="Enable {}".format(self.tabname), command=self.on_chkenable_change) chkenable.pack(side=tk.RIGHT, padx=5, anchor=tk.W) Tooltip(chkenable, text="Enable or disable {} display".format(self.tabname), wraplength=200)
Example #29
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, parent, label='', input_class=None, input_var=None, input_args=None, label_args=None, field_spec=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} if field_spec: field_type = field_spec.get('type', FT.string) input_class = input_class or self.field_types.get(field_type)[0] var_type = self.field_types.get(field_type)[1] self.variable = input_var if input_var else var_type() # min, max, increment if 'min' in field_spec and 'from_' not in input_args: input_args['from_'] = field_spec.get('min') if 'max' in field_spec and 'to' not in input_args: input_args['to'] = field_spec.get('max') if 'inc' in field_spec and 'increment' not in input_args: input_args['increment'] = field_spec.get('inc') # values if 'values' in field_spec and 'values' not in input_args: input_args['values'] = field_spec.get('values') else: self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = self.variable else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = self.variable self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error, **label_args) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #30
Source File: wb_runner.py From whitebox-python with MIT License | 5 votes |
def __init__(self, json_str, master=None): # first make sure that the json data has the correct fields j = json.loads(json_str) self.name = j['name'] self.description = j['description'] self.flag = j['flags'][len(j['flags']) - 1] self.parameter_type = j['parameter_type'] # just for quality control. BooleanInputs are always optional. self.optional = True default_value = j['default_value'] ttk.Frame.__init__(self, master) self.grid() self['padding'] = '0.05i' frame = ttk.Frame(self, padding='0.0i') self.value = tk.IntVar() c = ttk.Checkbutton(frame, text=self.name, width=55, variable=self.value) c.grid(row=0, column=0, sticky=tk.W) # set the default value if j['default_value'] != None and j['default_value'] != 'false': self.value.set(1) else: self.value.set(0) frame.grid(row=1, column=0, sticky=tk.W) frame.columnconfigure(0, weight=1) # self.pack(fill=tk.BOTH, expand=1) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1)