本文整理匯總了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')
示例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)
示例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))
示例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()
示例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)
示例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']))
示例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.
# ----------------------------------------------------------------------
示例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
示例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)
示例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")
示例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
示例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
示例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
示例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
示例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