本文整理汇总了Python中tkinter.Frame.nametowidget方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.nametowidget方法的具体用法?Python Frame.nametowidget怎么用?Python Frame.nametowidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Frame
的用法示例。
在下文中一共展示了Frame.nametowidget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tkinter import Frame [as 别名]
# 或者: from tkinter.Frame import nametowidget [as 别名]
class InitScreen:
def __init__(self, master):
self.funcs = {}
self.master = master
self.controller = InitScreenController(master)
self.master.title('parent')
self.master.geometry('640x480+200+150')
self.set_param_init()
self.frame.pack()
self.master.mainloop()
def set_param_init(self):
self.frame = Frame(width=400, height=300, bd=2)
self.frame.grid_bbox(2, 4 + default_fields_count)
self._buttons_init()
self.entrys = {}
_vcmd = self.frame.register(self._validate)
count = 0
for block_name, block in default_params.items():
Label(self.frame,
text=_convert(block_name),
background="#999",
justify=LEFT).grid(
row=count,
column=1
)
count += 1
for name, _default in block.items():
default, func = _default
Label(self.frame,
text=_convert(name),
justify=LEFT).grid(
row=count,
column=1
)
# self.entrys[_convert(name)] = ""
sv = StringVar(
value=default_params[block_name][name][0])
e = Entry(self.frame)
self.entrys[name] = sv
self.funcs[e] = func
e.config(validate='key',
vcmd=(_vcmd, "%P", "%W"),
textvariable=sv)
e.grid(row=count,
column=2)
count += 1
Label(self.frame,
text="Количество существ:",
justify=LEFT).grid(
row=count,
column=1
)
self.creature_count = \
Label(self.frame,
text='0',
justify=LEFT)
self.creature_count.grid(
row=count,
column=2
)
def _buttons_init(self):
self.load_button = Button(self.frame,
text='Загрузить',
command=self.load_button_press)
self.load_button.grid(row=4 + default_fields_count,
column=1)
self.start_button = Button(self.frame,
text='Старт',
command=self.start_button_press)
self.start_button.grid(row=4 + default_fields_count,
column=2)
self.master.protocol('WM_DELETE_WINDOW',
self.exit)
def _validate(self, P, W):
e = self.frame.nametowidget(W)
func = self.funcs[e]
try:
func(P)
except ValueError:
return False
#.........这里部分代码省略.........