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


Python ttk.Checkbutton方法代码示例

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


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

示例1: create_parameters_frame

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

示例2: set

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [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

示例3: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [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

示例4: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [as 别名]
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() 
开发者ID:TkinterEP,项目名称:ttkwidgets,代码行数:27,代码来源:toggledframe.py

示例5: on_select_box

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

示例6: test_invoke

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

示例7: button_pressed

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

示例8: get_control

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

示例9: build_one_control

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

示例10: opts_checkbuttons

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

示例11: __init__

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [as 别名]
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 
开发者ID:shitwolfymakes,项目名称:Endless-Sky-Mission-Builder,代码行数:22,代码来源:ComboComponentFrame.py

示例12: populate_trigger

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [as 别名]
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 
开发者ID:shitwolfymakes,项目名称:Endless-Sky-Mission-Builder,代码行数:20,代码来源:AggregatedTriggerFrame.py

示例13: _add_log

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [as 别名]
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 
开发者ID:shitwolfymakes,项目名称:Endless-Sky-Mission-Builder,代码行数:23,代码来源:AggregatedLogFrame.py

示例14: populate_log

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [as 别名]
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 
开发者ID:shitwolfymakes,项目名称:Endless-Sky-Mission-Builder,代码行数:20,代码来源:AggregatedLogFrame.py

示例15: populate_trigger_condition

# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Checkbutton [as 别名]
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 
开发者ID:shitwolfymakes,项目名称:Endless-Sky-Mission-Builder,代码行数:20,代码来源:AggregatedTriggerConditionFrame.py


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