本文整理匯總了Python中tkinter.ttk.OptionMenu方法的典型用法代碼示例。如果您正苦於以下問題:Python ttk.OptionMenu方法的具體用法?Python ttk.OptionMenu怎麽用?Python ttk.OptionMenu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tkinter.ttk
的用法示例。
在下文中一共展示了ttk.OptionMenu方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_parameters_frame
# 需要導入模塊: from tkinter import ttk [as 別名]
# 或者: from tkinter.ttk import OptionMenu [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: de_widget
# 需要導入模塊: from tkinter import ttk [as 別名]
# 或者: from tkinter.ttk import OptionMenu [as 別名]
def de_widget(self):
# Initialize widget
self.init_widget()
# strategy
self.strategy_label = ttk.Label(self.frame1.sliders, text = "Strategy")
self.strategy_option_menu = ttk.OptionMenu(self.frame1.sliders, self.strategy, self.strategy.get(),
*sorted(self.STRATOPT))
self.strategy_label.place(relx = 0, x = 0, y = 5, anchor = "nw")
self.strategy_option_menu.place(relx = 0, x = 70, y = 3, anchor = "nw")
# CR
self._label("Crossover probability", 2)
self._scale(0., 1., 0.01, self.CR, 2)
self._entry(self.CR, 2)
# F
self._label("Differential weight", 4)
self._scale(0., 2., 0.01, self.F, 4)
self._entry(self.F, 4)
示例3: test_widget_destroy
# 需要導入模塊: from tkinter import ttk [as 別名]
# 或者: from tkinter.ttk import OptionMenu [as 別名]
def test_widget_destroy(self):
var = tkinter.StringVar(self.root)
optmenu = ttk.OptionMenu(self.root, var)
name = var._name
optmenu.update_idletasks()
optmenu.destroy()
self.assertEqual(optmenu.tk.globalgetvar(name), var.get())
del var
self.assertRaises(tkinter.TclError, optmenu.tk.globalgetvar, name)
示例4: test_initialization
# 需要導入模塊: from tkinter import ttk [as 別名]
# 或者: from tkinter.ttk import OptionMenu [as 別名]
def test_initialization(self):
self.assertRaises(tkinter.TclError,
ttk.OptionMenu, self.root, self.textvar, invalid='thing')
optmenu = ttk.OptionMenu(self.root, self.textvar, 'b', 'a', 'b')
self.assertEqual(optmenu._variable.get(), 'b')
self.assertTrue(optmenu['menu'])
self.assertTrue(optmenu['textvariable'])
optmenu.destroy()
示例5: frame1
# 需要導入模塊: from tkinter import ttk [as 別名]
# 或者: from tkinter.ttk import OptionMenu [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")
示例6: test_menu
# 需要導入模塊: from tkinter import ttk [as 別名]
# 或者: from tkinter.ttk import OptionMenu [as 別名]
def test_menu(self):
items = ('a', 'b', 'c')
default = 'a'
optmenu = ttk.OptionMenu(self.root, self.textvar, default, *items)
found_default = False
for i in range(len(items)):
value = optmenu['menu'].entrycget(i, 'value')
self.assertEqual(value, items[i])
if value == default:
found_default = True
self.assertTrue(found_default)
optmenu.destroy()
# default shouldn't be in menu if it is not part of values
default = 'd'
optmenu = ttk.OptionMenu(self.root, self.textvar, default, *items)
curr = None
i = 0
while True:
last, curr = curr, optmenu['menu'].entryconfigure(i, 'value')
if last == curr:
# no more menu entries
break
self.assertNotEqual(curr, default)
i += 1
self.assertEqual(i, len(items))
# check that variable is updated correctly
optmenu.pack()
optmenu.wait_visibility()
optmenu['menu'].invoke(0)
self.assertEqual(optmenu._variable.get(), items[0])
# changing to an invalid index shouldn't change the variable
self.assertRaises(tkinter.TclError, optmenu['menu'].invoke, -1)
self.assertEqual(optmenu._variable.get(), items[0])
optmenu.destroy()
# specifying a callback
success = []
def cb_test(item):
self.assertEqual(item, items[1])
success.append(True)
optmenu = ttk.OptionMenu(self.root, self.textvar, 'a', command=cb_test,
*items)
optmenu['menu'].invoke(1)
if not success:
self.fail("Menu callback not invoked")
optmenu.destroy()