【发布时间】:2018-01-04 21:47:28
【问题描述】:
我是 Python 新手,即将使用 tkinter 构建一个 GUI。 GUI 由一个笔记本组成,我正在尝试为用户在不同选项卡上单击鼠标时创建一个事件处理程序。但是,当我单击一个选项卡时,处理函数“工作”,但似乎在调用该函数之前所选选项卡没有“更新”。
作为旁注:到目前为止,我主要使用了 'Tkinter 8.5 reference: a GUI for 蟒蛇(船夫)'。请看下面的代码。感谢任何建议!
from tkinter import *
import tkinter.ttk as ttk
root = Tk()
note = ttk.Notebook(root)
tab1 = Frame(note,width = 10)
tab2 = Frame(note,width = 10)
tab3 = Frame(note,width = 10)
note.add(tab1, text = "Tab One")
note.add(tab2, text = "Tab Two")
note.add(tab3, text = "Tab Three")
note.grid()
def personalData(event):
if event.widget.index("current") == 0:
print("One!")
else:
print("Not One!")
note.bind('<1>',personalData)
root.mainloop()
【问题讨论】:
-
note.bind('<<NotebookTabChanged>>',personalData)