本文整理汇总了Python中ttk.Checkbutton方法的典型用法代码示例。如果您正苦于以下问题:Python ttk.Checkbutton方法的具体用法?Python ttk.Checkbutton怎么用?Python ttk.Checkbutton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ttk
的用法示例。
在下文中一共展示了ttk.Checkbutton方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invoke
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def test_invoke(self):
success = []
def cb_test():
success.append(1)
return "cb test called"
cbtn = ttk.Checkbutton(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.assertEqual(res, '')
self.assertFalse(len(success) > 1)
self.assertEqual(cbtn['offvalue'],
cbtn.tk.globalgetvar(cbtn['variable']))
示例2: test_invoke
# 需要导入模块: import ttk [as 别名]
# 或者: from 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']))
示例3: __init__
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def __init__(self, master=None, **kw):
if platform == 'darwin':
kw['foreground'] = kw.pop('foreground', PAGEFG)
kw['background'] = kw.pop('background', PAGEBG)
tk.Checkbutton.__init__(self, master, **kw)
elif platform == 'win32':
ttk.Checkbutton.__init__(self, master, style='nb.TCheckbutton', **kw)
else:
ttk.Checkbutton.__init__(self, master, **kw)
示例4: preferences
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
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
#
示例5: create
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def create(self, **kwargs):
return ttk.Checkbutton(self.root, **kwargs)
示例6: show_window
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def show_window(self):
self.mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
self.mainframe.columnconfigure(0, weight=1)
self.mainframe.rowconfigure(0, weight=1)
ttk.Label(self.mainframe, text=" ").grid(column=0, row=0, sticky=(N,W))
ttk.Label(self.mainframe, text='1. Pair your Light Panels ').grid(column=1, row=1, sticky=(N, W))
ttk.Checkbutton(self.mainframe, variable=self.should_use_simulator, text='Use Light Panels Simulator', command=self.toggle_aurora_simulator).grid(column=2, row=1, sticky=(N,W))
ttk.Label(self.mainframe, text='IP Address').grid(column=1, row=2, sticky=(N, W))
self.pair_entry = ttk.Entry(self.mainframe, width=35, textvariable=self.ip_addr)
self.pair_entry.grid(column=2, row=2, columnspan=2, sticky=(N, W))
self.pair_button = ttk.Button(self.mainframe, width=12, text='Pair', command=self.authenticate_with_aurora)
self.pair_button.grid(column=4, row=2, sticky=(N,W))
ttk.Label(self.mainframe, text='2. Make a color palette').grid(column=1, row=3, sticky=(N, W))
ttk.Button(self.mainframe, text="Add Color", command=self.add_color_to_palette).grid(column=1, row=4, sticky=(N, W))
ttk.Label(self.mainframe, textvariable=self.curr_palette_string, wraplength=500).grid(column=2, row=4, columnspan=2, sticky=(N, W))
ttk.Button(self.mainframe, width=12, text="Clear palette", command=self.clear_palette).grid(column=4, row=4, sticky=(N, W))
ttk.Label(self.mainframe, text='3. Build your plugin').grid(column=1, row=5, sticky=(N, W))
ttk.Label(self.mainframe, text='Plugin Location').grid(column=1, row=6, sticky=(N, W))
ttk.Entry(self.mainframe, width=35, textvariable=self.plugin_dir_path).grid(column=2, row=6, columnspan=2, sticky=(N, W))
ttk.Button(self.mainframe, width=12, text='Browse', command=self.get_plugin_dir).grid(column=4, row=6, sticky=(N, W))
ttk.Button(self.mainframe, text='Build', command=self.build_plugin).grid(column=2, row=7, columnspan=1, sticky=(N,E))
ttk.Button(self.mainframe, text='Upload & Run', command=self.play_plugin).grid(column=3, row=7, columnspan=1, sticky=N)
ttk.Button(self.mainframe, width=12, text='Stop Plugin', command=self.stop_plugin).grid(column=4, row=7, columnspan=1, sticky=(N, W))
ttk.Label(self.mainframe, text=" ").grid(column=5, row=8, sticky=(N,W))
ttk.Label(self.mainframe, text=" ").grid(column=5, row=9, sticky=(N,W))
self.pluginOptionsGUI.create_plugin_frame()
self.root.mainloop()
示例7: frame1_sync
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def frame1_sync(self):
if not self.frame1.first_run:
self.frame1.sync.forget()
self.frame1.sync = ttk.Frame(self.frame1, borderwidth = 0)
self.frame1.sync.place(width = 170, height = 25, relx = 0.35, y = 55, anchor = "nw")
if self.solver_name.get() in [ "CPSO", "PSO", "DE" ]:
# sync
sync_button = ttk.Checkbutton(self.frame1.sync, text = "Synchronize",
variable = self.sync, takefocus = False)
# Layout
sync_button.place(relx = 0, x =0, y = 0, anchor = "nw")
示例8: body
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def body(self, master, row, columns=DEFAULT_COLUMNS, **kwargs):
"""
Place the required elements using the grid layout method.
Returns the number of rows taken by this element.
"""
self.checkbox = ttk.Checkbutton(master, text=self.text, variable=self.value)
self.checkbox.grid(row=row, column=0, columnspan=columns, sticky="w")
return 1
示例9: create_play_bar
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def create_play_bar(self):
playbar_frame = Frame(self.root)
playbar_frame.grid(row=12, column=0,columnspan=13, sticky=W+E, padx=10, pady=5)
self.start_button = ttk.Button(playbar_frame, text='Play', command=self.play_in_threading)
self.start_button.grid(row=0, column=0, padx=2, pady=2)
button = ttk.Button(playbar_frame, text='Stop', command=self.stop_play)
button.grid(row=0, column=1, padx=2, pady=2)
loop = BooleanVar()
loopbutton = ttk.Checkbutton(playbar_frame, text='Loop', variable=loop, command=lambda:self.loop_play(loop.get()))
loopbutton.grid(row=0, column=2, padx=2, pady=2)
photo = PhotoImage(file='images/sig.gif')
label = Label(playbar_frame, image=photo)
label.image = photo
label.grid(row=0, column=3, padx=2, sticky=E)
示例10: openurl
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def openurl(self, event=None):
import urllib
toplevel = tkinter.Toplevel()
self.url = tkinter.StringVar()
def cancel(event=None):
self.url.set("")
toplevel.destroy()
def ok(event=None):
document = sem.importers.from_url(self.url.get(), wikinews_format=bool(self.wikinews_format.get()), strip_html=True)
if document is None: return
added = self.add_document(document)
if not added: return
self.load_document()
self.train_btn.configure(state=tkinter.NORMAL)
self.file_menu.entryconfig("Save to...", state=tkinter.NORMAL)
self.file_menu.entryconfig("Save as...", state=tkinter.NORMAL)
cancel()
label1 = tkinter.Label(toplevel, text="enter url:")
label1.pack()
text = ttk.Entry(toplevel, textvariable=self.url)
text.pack()
text.focus_set()
c = ttk.Checkbutton(toplevel, text="Use Wikinews format", variable=self.wikinews_format)
c.pack()
toolbar = ttk.Frame(toplevel)
toolbar.pack(side="top", fill="x")
ok_btn = ttk.Button(toolbar, text="OK", command=ok)
ok_btn.pack(side="left")
cancel_btn = ttk.Button(toolbar, text="cancel", command=cancel)
cancel_btn.pack(side="left")
toplevel.bind('<Return>', ok)
toplevel.bind('<Escape>', cancel)
toolbar.pack()
示例11: create_string_plugin_option_row
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def create_string_plugin_option_row(self, pluginOptionType, pluginOptionFrame, pluginOptionTypeVar, row=-1, defaultVal="", enabledOptionsVals=[]):
if not self.plugin_option_is_type_string(pluginOptionType):
return
column = 1
pluginOptionDefaultValue = StringVar()
enabledOptions = []
if pluginOptionType == OPTION_LINDIR:
ttk.Label(pluginOptionFrame, text='Enabled:').grid(column=column, row=row, sticky=(E))
column += 1
defaultOptions = self.linDirectionOptions
for value in defaultOptions:
index = defaultOptions.index(value)
isEnabled = IntVar()
if len(enabledOptionsVals) == 4:
isEnabled.set(enabledOptionsVals[index])
else:
isEnabled.set(1)
enabledOptions.append(isEnabled)
ttk.Checkbutton(pluginOptionFrame, variable=enabledOptions[index], text=value).grid(column=column, row=row)
column += 1
elif pluginOptionType == OPTION_RADDIR or pluginOptionType == OPTION_ROTDIR:
ttk.Label(pluginOptionFrame, text=' ').grid(column=1, row=row)
ttk.Label(pluginOptionFrame, text=' ').grid(column=2, row=row)
ttk.Label(pluginOptionFrame, text=' ').grid(column=3, row=row)
ttk.Label(pluginOptionFrame, text=' ').grid(column=4, row=row)
ttk.Label(pluginOptionFrame, text=' ').grid(column=5, row=row)
if pluginOptionType == OPTION_RADDIR:
defaultOptions = self.radDirectionOptions
elif pluginOptionType == OPTION_ROTDIR:
defaultOptions = self.rotDirectionOptions
if defaultVal and defaultVal in defaultOptions:
pluginOptionDefaultValue.set(defaultVal)
else:
pluginOptionDefaultValue.set(defaultOptions[0])
ttk.Label(pluginOptionFrame, text='Default Value:').grid(column=6, row=row, sticky=(E))
column += 1
optionmenu = OptionMenu(pluginOptionFrame, pluginOptionDefaultValue, *defaultOptions)
optionmenu.grid(column=7, row=row)
# Known issue with MacOS TCL where the background color of ttk is not defined and different from the Tkinter background color
operating_sys = sys.platform
if operating_sys == "darwin":
optionmenu.configure(background="#E4E4E4")
column += 1
pluginOptionRow = {
"rowFrame": pluginOptionFrame,
"optionTypeVar": pluginOptionTypeVar,
"optionDefaultVar": pluginOptionDefaultValue
}
if pluginOptionType == OPTION_LINDIR:
pluginOptionRow["enabledOptionsVars"] = enabledOptions;
ttk.Button(pluginOptionFrame, text='Remove', command=lambda: self.remove_plugin_option(pluginOptionRow)).grid(column=8, row=row, sticky=(E))
column += 1
return pluginOptionRow
示例12: frame1
# 需要导入模块: import ttk [as 别名]
# 或者: from ttk import Checkbutton [as 别名]
def frame1(self):
self.frame1 = ttk.LabelFrame(self.master, text = "Parameters", borderwidth = 2, relief = "groove")
self.frame1.place(bordermode = "outside", relwidth = 0.99, relheight = 0.21, relx = 0, x = 5, y = 5, anchor = "nw")
self.frame1.first_run = True
# function
function_label = ttk.Label(self.frame1, text = "Function")
function_option_menu = ttk.OptionMenu(self.frame1, self.function, self.function.get(),
*sorted(self.FUNCOPT))
# max_iter
max_iter_label = ttk.Label(self.frame1, text = "Maximum number of iterations")
max_iter_spinbox = Spinbox(self.frame1, from_ = 2, to_ = 9999,
increment = 1, textvariable = self.max_iter,
width = 6, justify = "right", takefocus = True)
# fps
fps_label = ttk.Label(self.frame1, text = "Delay between frames (ms)")
fps_spinbox = Spinbox(self.frame1, from_ = 1, to_ = 1000,
increment = 1, textvariable = self.interval,
width = 6, justify = "right", takefocus = True)
# seed
seed_button = ttk.Checkbutton(self.frame1, text = "Fix seed",
variable = self.fix_seed, takefocus = False)
seed_spinbox = Spinbox(self.frame1, from_ = 0, to_ = self.MAX_SEED,
increment = 1, textvariable = self.seed,
width = 6, justify = "right", takefocus = True)
# solver
solver_label = ttk.Label(self.frame1, text = "Solver")
solver_option_menu = ttk.OptionMenu(self.frame1, self.solver_name, self.solver_name.get(),
*(self.EAOPT + self.MCOPT), command = self.select_widget)
# constrain
constrain_button = ttk.Checkbutton(self.frame1, text = "Constrain",
variable = self.constrain, takefocus = False)
# Layout
function_label.place(relx = 0., x = 5, y = 5, anchor = "nw")
function_option_menu.place(relx = 0., x = 75, y = 3, anchor = "nw")
max_iter_label.place(relx = 0., x = 5, y = 30, anchor = "nw")
max_iter_spinbox.place(width = 80, relx = 0., x = 220, y = 30, anchor = "nw")
fps_label.place(relx = 0., x = 5, y = 55, anchor = "nw")
fps_spinbox.place(width = 80, relx = 0., x = 220, y = 55, anchor = "nw")
seed_button.place(relx = 0., x = 5, y = 80, anchor = "nw")
seed_spinbox.place(width = 80, relx = 0., x = 220, y = 80, anchor = "nw")
solver_label.place(relx = 0.35, x = 0, y = 5, anchor = "nw")
solver_option_menu.place(relx = 0.35, x = 50, y = 3, anchor = "nw")
constrain_button.place(relx = 0.35, x = 0, y = 80, anchor = "nw")