当前位置: 首页>>代码示例>>Python>>正文


Python ttk.Radiobutton方法代码示例

本文整理汇总了Python中tkinter.ttk.Radiobutton方法的典型用法代码示例。如果您正苦于以下问题:Python ttk.Radiobutton方法的具体用法?Python ttk.Radiobutton怎么用?Python ttk.Radiobutton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.ttk的用法示例。


在下文中一共展示了ttk.Radiobutton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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) 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:18,代码来源:widgets.py

示例2: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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)) 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:24,代码来源:data_entry_app.py

示例3: _create_file_format_btn

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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) 
开发者ID:araith,项目名称:pyDEA,代码行数:18,代码来源:solution_tab_frame_gui.py

示例4: radio_btn_change

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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') 
开发者ID:araith,项目名称:pyDEA,代码行数:24,代码来源:options_frame_gui.py

示例5: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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) 
开发者ID:adipandas,项目名称:python-gui-demos,代码行数:40,代码来源:program5.py

示例6: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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)) 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:40,代码来源:widgets.py

示例7: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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)) 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:40,代码来源:widgets.py

示例8: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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)) 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:41,代码来源:widgets.py

示例9: _create_frame_with_radio_btns

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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) 
开发者ID:araith,项目名称:pyDEA,代码行数:39,代码来源:options_frame_gui.py

示例10: create

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
def create(self, **kwargs):
        return ttk.Radiobutton(self.root, **kwargs) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_widgets.py

示例11: test_invoke

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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'])) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:35,代码来源:test_widgets.py

示例12: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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) 
开发者ID:irmen,项目名称:synthesizer,代码行数:36,代码来源:box.py

示例13: _multi_option_control

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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 
开发者ID:deepfakes,项目名称:faceswap,代码行数:34,代码来源:control_helper.py

示例14: build_input_frame

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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) 
开发者ID:PacktPublishing,项目名称:Learning-Python-for-Forensics-Second-Edition,代码行数:36,代码来源:date_decoder.py

示例15: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Radiobutton [as 别名]
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") 
开发者ID:thonny,项目名称:thonny,代码行数:35,代码来源:ui_utils.py


注:本文中的tkinter.ttk.Radiobutton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。