本文整理汇总了Python中tkinter.Label.callback方法的典型用法代码示例。如果您正苦于以下问题:Python Label.callback方法的具体用法?Python Label.callback怎么用?Python Label.callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Label
的用法示例。
在下文中一共展示了Label.callback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import callback [as 别名]
def __init__(self, game, stats=DEFAULT_STATS, buttons=DEFAULT_BUTTONS_CONTINUE):
self.action = None
self.root = root = Tk()
root.title("Iä! Shub-Niggurath! The Black Goat of the Woods with a Thousand Young!")
root.protocol("WM_DELETE_WINDOW", self.close)
root.pack_propagate(True)
self.grid_canvas = Canvas(root, bd=5, relief=tkinter.SUNKEN)
self.grid_canvas.pack(expand=True, fill=tkinter.BOTH, side=tkinter.LEFT)
button_frame = Frame(root)
button_frame.pack(fill=tkinter.BOTH, side=tkinter.LEFT)
stat_frame = Frame(button_frame, bd=1)
stat_frame.pack(fill=tkinter.BOTH)
stat_frame.columnconfigure(1, weight=1)
self.stat_textboxes = stat_textboxes = []
for row, (text, callback) in enumerate(stats):
label = Label(stat_frame, text=text + ":", anchor="e")
label.grid(row=row, column=0, sticky="wens")
textbox = Label(stat_frame, bd=1, relief=tkinter.SUNKEN)
textbox.callback = callback # for our own use.
textbox.grid(row=row, column=1, sticky="wens")
stat_textboxes.append(textbox)
for name, bindings, action in buttons:
def callback(event, action=action):
if self.action is not None:
log.error("Action already set: %r when processing %r", self.action, action)
self.action = action
root.quit()
text = name + (" ({})".format(bindings) if bindings else "")
button = Button(button_frame, text=text, command=lambda: callback(None))
button.pack()
for it in bindings.split():
root.bind(it, callback)
if game is not None:
self.update(game)