Python tkinter.ttk.Radiobutton() Examples
The following are 30
code examples of tkinter.ttk.Radiobutton().
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: 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 #2
Source File: options_frame_gui.py From pyDEA with MIT License | 6 votes |
def radio_btn_change(self, name, *args): ''' Actions that happen when user clicks on a Radiobutton. Changes the corresponding parameter values and options. Args: name (str): name of the parameter that is a key in options dictionary. *args: are provided by IntVar trace method and are ignored in this method. ''' count = self.options[name].get() self.params.update_parameter(name, COUNT_TO_NAME_RADIO_BTN[name, count]) dea_form = COUNT_TO_NAME_RADIO_BTN[name, count] if self.max_slack_box: # on creation it is None if dea_form == 'multi': # disable max slacks self.max_slack_box.config(state=DISABLED) self.params.update_parameter('MAXIMIZE_SLACKS', '') elif dea_form == 'env': self.max_slack_box.config(state=NORMAL) if self.options['MAXIMIZE_SLACKS'].get() == 1: self.params.update_parameter('MAXIMIZE_SLACKS', 'yes')
Example #3
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 #4
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 #5
Source File: solution_tab_frame_gui.py From pyDEA with MIT License | 6 votes |
def _create_file_format_btn(self, btn_text, var_value, parent, column): ''' Creates and grids Radiobutton used for choosing solution file format. Args: btn_text (str): text displayed next to the Radiobutton. var_value (int): value of the IntVar associated with this Radiobutton. parent (Tk object): parent of this Radiobutton. column (int): column index where this Radiobutton should be gridded. ''' sol_format_btn = Radiobutton(parent, text=btn_text, variable=self.solution_format_var, value=var_value) sol_format_btn.grid(row=2, column=column, sticky=W+N, padx=2)
Example #6
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 #7
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 #8
Source File: control_helper.py From faceswap with GNU General Public License v3.0 | 5 votes |
def _multi_option_control(self, option_type): """ Create a group of buttons for single or multi-select Parameters ---------- option_type: {"radio", "multi"} The type of boxes that this control should hold. "radio" for single item select, "multi" for multi item select. """ logger.debug("Adding %s group: %s", option_type, self.option.name) help_intro, help_items = self._get_multi_help_items(self.option.helptext) ctl = ttk.LabelFrame(self.frame, text=self.option.title, name="{}_labelframe".format(option_type)) holder = AutoFillContainer(ctl, self.option_columns, self.option_columns) for choice in self.option.choices: ctl = ttk.Radiobutton if option_type == "radio" else MultiOption ctl = ctl(holder.subframe, text=choice.replace("_", " ").title(), value=choice, variable=self.option.tk_var) if choice.lower() in help_items: self.helpset = True helptext = help_items[choice.lower()].capitalize() helptext = "{}\n\n - {}".format( '. '.join(item.capitalize() for item in helptext.split('. ')), help_intro) _get_tooltip(ctl, text=helptext, wraplength=600) ctl.pack(anchor=tk.W) logger.debug("Added %s option %s", option_type, choice) return holder.parent
Example #9
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def create(self, **kwargs): return ttk.Radiobutton(self.root, **kwargs)
Example #10
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_invoke(self): success = [] def cb_test(): success.append(1) return "cb test called" myvar = tkinter.IntVar(self.root) cbtn = ttk.Radiobutton(self.root, command=cb_test, variable=myvar, value=0) cbtn2 = ttk.Radiobutton(self.root, command=cb_test, variable=myvar, value=1) if self.wantobjects: conv = lambda x: x else: conv = int res = cbtn.invoke() self.assertEqual(res, "cb test called") self.assertEqual(conv(cbtn['value']), myvar.get()) self.assertEqual(myvar.get(), conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertTrue(success) cbtn2['command'] = '' res = cbtn2.invoke() self.assertEqual(str(res), '') self.assertLessEqual(len(success), 1) self.assertEqual(conv(cbtn2['value']), myvar.get()) self.assertEqual(myvar.get(), conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
Example #11
Source File: test_widgets.py From ironpython3 with Apache License 2.0 | 5 votes |
def create(self, **kwargs): return ttk.Radiobutton(self.root, **kwargs)
Example #12
Source File: test_widgets.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_invoke(self): success = [] def cb_test(): success.append(1) return "cb test called" myvar = tkinter.IntVar(self.root) cbtn = ttk.Radiobutton(self.root, command=cb_test, variable=myvar, value=0) cbtn2 = ttk.Radiobutton(self.root, command=cb_test, variable=myvar, value=1) if self.wantobjects: conv = lambda x: x else: conv = int res = cbtn.invoke() self.assertEqual(res, "cb test called") self.assertEqual(conv(cbtn['value']), myvar.get()) self.assertEqual(myvar.get(), conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertTrue(success) cbtn2['command'] = '' res = cbtn2.invoke() self.assertEqual(str(res), '') self.assertLessEqual(len(success), 1) self.assertEqual(conv(cbtn2['value']), myvar.get()) self.assertEqual(myvar.get(), conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
Example #13
Source File: box.py From synthesizer with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, app, master): super().__init__(master, text="Search song", padding=4) self.app = app self.search_text = tk.StringVar() self.filter_choice = tk.StringVar(value="title") bf = ttk.Frame(self) ttk.Label(bf, text="Search for:").pack() e = ttk.Entry(bf, textvariable=self.search_text) e.bind("<Return>", self.do_search) e.bind("<KeyRelease>", self.on_key_up) self.search_job = None e.pack() ttk.Radiobutton(bf, text="title", value="title", variable=self.filter_choice, width=10).pack() ttk.Radiobutton(bf, text="artist", value="artist", variable=self.filter_choice, width=10).pack() ttk.Radiobutton(bf, text="album", value="album", variable=self.filter_choice, width=10).pack() ttk.Radiobutton(bf, text="year", value="year", variable=self.filter_choice, width=10).pack() ttk.Radiobutton(bf, text="genre", value="genre", variable=self.filter_choice, width=10).pack() ttk.Button(bf, text="Search", command=self.do_search).pack() ttk.Button(bf, text="Add all selected", command=self.do_add_selected).pack() bf.pack(side=tk.LEFT) sf = ttk.Frame(self) cols = [("title", 320), ("artist", 200), ("album", 200), ("year", 60), ("genre", 160), ("length", 80)] self.resultTreeView = ttk.Treeview(sf, columns=[col for col, _ in cols], height=16, show="headings") vsb = ttk.Scrollbar(orient="vertical", command=self.resultTreeView.yview) self.resultTreeView.configure(yscrollcommand=vsb.set) self.resultTreeView.grid(column=1, row=0, sticky=tk.NSEW, in_=sf) vsb.grid(column=0, row=0, sticky=tk.NS, in_=sf) for col, colwidth in cols: self.resultTreeView.heading(col, text=col.title(), command=lambda c=col: self.sortby(self.resultTreeView, c, 0)) self.resultTreeView.column(col, width=colwidth) self.resultTreeView.bind("<Double-1>", self.on_doubleclick) sf.grid_columnconfigure(0, weight=1) sf.grid_rowconfigure(0, weight=1) sf.pack(side=tk.LEFT, padx=4)
Example #14
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 #15
Source File: test_widgets.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def create(self, **kwargs): return ttk.Radiobutton(self.root, **kwargs)
Example #16
Source File: test_widgets.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_invoke(self): success = [] def cb_test(): success.append(1) return "cb test called" myvar = tkinter.IntVar(self.root) cbtn = ttk.Radiobutton(self.root, command=cb_test, variable=myvar, value=0) cbtn2 = ttk.Radiobutton(self.root, command=cb_test, variable=myvar, value=1) if self.wantobjects: conv = lambda x: x else: conv = int res = cbtn.invoke() self.assertEqual(res, "cb test called") self.assertEqual(conv(cbtn['value']), myvar.get()) self.assertEqual(myvar.get(), conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertTrue(success) cbtn2['command'] = '' res = cbtn2.invoke() self.assertEqual(str(res), '') self.assertLessEqual(len(success), 1) self.assertEqual(conv(cbtn2['value']), myvar.get()) self.assertEqual(myvar.get(), conv(cbtn.tk.globalgetvar(cbtn['variable']))) self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
Example #17
Source File: date_decoder.py From Learning-Python-for-Forensics-Second-Edition with MIT License | 5 votes |
def build_input_frame(self): """ The build_input_frame method builds the interface for the input frame """ # Frame Init self.input_frame = ttk.Frame(self.root) self.input_frame.config(padding = (30,0)) self.input_frame.pack() # Input Value ttk.Label(self.input_frame, text="Enter Time Value").grid(row=0, column=0) self.input_time = StringVar() ttk.Entry(self.input_frame, textvariable=self.input_time, width=25).grid(row=0, column=1, padx=5) # Radiobuttons self.time_type = StringVar() self.time_type.set('raw') ttk.Radiobutton(self.input_frame, text="Raw Value", variable=self.time_type, value="raw").grid(row=1, column=0, padx=5) ttk.Radiobutton(self.input_frame, text="Formatted Value", variable=self.time_type, value="formatted").grid( row=1, column=1, padx=5) # Button ttk.Button(self.input_frame, text="Run", command=self.convert).grid( row=2, columnspan=2, pady=5)
Example #18
Source File: ui_utils.py From thonny with MIT License | 5 votes |
def __init__( self, master=None, title="Choose one", question: str = "Choose one:", choices=[] ) -> None: super().__init__(master=master) self.title(title) self.resizable(False, False) self.columnconfigure(0, weight=1) row = 0 question_label = ttk.Label(self, text=question) question_label.grid(row=row, column=0, columnspan=2, sticky="w", padx=20, pady=20) row += 1 self.var = tk.StringVar() for choice in choices: rb = ttk.Radiobutton(self, text=choice, variable=self.var, value=choice) rb.grid(row=row, column=0, columnspan=2, sticky="w", padx=20) row += 1 ok_button = ttk.Button(self, text="OK", command=self._ok, default="active") ok_button.grid(row=row, column=0, sticky="e", pady=20) cancel_button = ttk.Button(self, text="Cancel", command=self._cancel) cancel_button.grid(row=row, column=1, sticky="e", padx=20, pady=20) self.bind("<Escape>", self._cancel, True) self.bind("<Return>", self._ok, True) self.protocol("WM_DELETE_WINDOW", self._cancel) if misc_utils.running_on_mac_os(): self.configure(background="systemSheetBackground")
Example #19
Source File: options_frame_gui.py From pyDEA with MIT License | 5 votes |
def _create_frame_with_radio_btns(self, parent, name, text, row_index, column_index, add_both=True): ''' Creates frame with one set of Radiobuttons. Args: parent (Tk object): parent of the frame. name (str): name of the parameter that will a key in options dictionary. text (list of str): list with two parameter values that should be displayed next to the first two Radiobuttons. row_index (int): index of the row where the frame should be placed using grid method. column_index (int): index of the column where the frame should be placed using grid method. add_both (bool, optional): True if the third Radiobutton with text "both" must be displayed, False otherwise, defaults to True. ''' assert len(text) == 2 v = IntVar() self.options[name] = v self.options[name].trace( 'w', (lambda *args: self.radio_btn_change(name))) frame_with_radio_btns = Frame(parent) first_option = Radiobutton(frame_with_radio_btns, text=text[0], variable=v, value=1) first_option.grid(row=0, column=0, sticky=W+N, padx=2) v.set(1) second_option = Radiobutton(frame_with_radio_btns, text=text[1], variable=v, value=2) second_option.grid(row=1, column=0, sticky=W+N, padx=2) if add_both: both = Radiobutton(frame_with_radio_btns, text='Both', variable=v, value=3) both.grid(row=3, column=0, sticky=W+N, padx=2) frame_with_radio_btns.grid(row=row_index, column=column_index, padx=1, pady=5, sticky=W+N)
Example #20
Source File: program5.py From python-gui-demos with MIT License | 5 votes |
def __init__(self, master): # More advanced as compared to regular buttons # Check buttons can also store binary values self.checkbutton = ttk.Checkbutton(master, text = 'Check Me!') self.checkbutton.pack() self.label = ttk.Label(master, text = 'Ready!! Nothing has happened yet.') self.label.pack() # Tkinter variable classes # self.boolvar = tk.BooleanVar() # boolean type variable of tk # self.dblvar = tk.DoubleVar() # double type variable of tk # self.intvar = tk.IntVar() # int type variable of tk self.checkme = tk.StringVar() # string type variable of tk self.checkme.set('NULL') # set value for string type tkinter variable print('Current value of checkme variable is \'{}\''.format(self.checkme.get())) # setting of binary value for check button: 1. onvaalue and 2. offvalue self.checkbutton.config(variable = self.checkme, onvalue = 'I am checked!!', offvalue = 'Waiting for someone to check me!') self.checkbutton.config(command = self.oncheckme) # creating another tkinter string type variable - StringVar self.papertype = tk.StringVar() # created a variable self.radiobutton1 = ttk.Radiobutton(master, text = 'Paper1', variable=self.papertype, value = 'Robotics Research') self.radiobutton1.config(command = self.onselectradio) self.radiobutton1.pack() self.radiobutton2 = ttk.Radiobutton(master, text = 'Paper2', variable=self.papertype, value = 'Solid Mechanics Research') self.radiobutton2.config(command = self.onselectradio) self.radiobutton2.pack() self.radiobutton3 = ttk.Radiobutton(master, text = 'Paper3', variable=self.papertype, value = 'Biology Research') self.radiobutton3.config(command = self.onselectradio) self.radiobutton3.pack() self.radiobutton4 = ttk.Radiobutton(master, text = 'Paper4', variable=self.papertype, value = 'SPAM Research') self.radiobutton4.config(command = self.onselectradio) self.radiobutton4.pack() self.radiobutton5 = ttk.Radiobutton(master, text = 'Change Checkme text', variable=self.papertype, value = 'Radio Checkme Selected') self.radiobutton5.pack() self.radiobutton5.config(command = self.onradiobuttonselect)
Example #21
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 #22
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 #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: 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 #26
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 #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, **label_args) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #28
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 #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) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #30
Source File: m6e_checkbox_and_radio_buttons.py From TkinterPractice with MIT License | 4 votes |
def main(): # Thus usual root and main Frame. root = tkinter.Tk() mainframe = ttk.Frame(root, padding=20) mainframe.grid() # Checkbutton's and Radiobutton's have their own labels. checkbutton = ttk.Checkbutton(mainframe, text='Robots rule!') # Radiobutton's. We often put them onto a sub-frame, # to group them visually. The 'value' identifies which is selected. radio_frame = ttk.Frame(mainframe, borderwidth=10, relief='groove') radio1 = ttk.Radiobutton(radio_frame, text='Peter Pevensie', value='peter') radio2 = ttk.Radiobutton(radio_frame, text='Susan Pevensie', value='susan') radio3 = ttk.Radiobutton(radio_frame, text='Edmund Pevensie', value='edmund') radio4 = ttk.Radiobutton(radio_frame, text='Lucy Pevensie', value='lucy') # This Button will show how it can interact with other widgets. button = ttk.Button(mainframe, text='Reset the other widgets') # Checkbutton's and Radiobutton's can have an "observer" variable # that is bound to the state of the Checkbutton / Radiobutton. checkbutton_observer = tkinter.StringVar() checkbutton['variable'] = checkbutton_observer radio_observer = tkinter.StringVar() for radio in [radio1, radio2, radio3, radio4]: radio['variable'] = radio_observer # They all need the SAME observer # Bind callbacks using 'command' and lambda, as we have seen elsewhere. checkbutton['command'] = lambda: checkbutton_changed(checkbutton_observer) for radio in [radio1, radio2, radio3, radio4]: radio['command'] = lambda: radiobutton_changed(radio_observer) button['command'] = lambda: button_pressed(checkbutton_observer, radio_observer) # Layout the widgets (here, in a row with padding between them). # You can see more on layout in a subsequent example. c = 0 for widget in [checkbutton, radio_frame, button]: widget.grid(row=0, column=c, padx=20) c = c + 1 for radio in [radio1, radio2, radio3, radio4]: radio.grid(sticky='w') root.mainloop()