这是我的代码..我需要事件绑定同时适用于所有选项卡..问题是当生成新选项卡时,事件绑定将与最后生成的选项卡相关,并且不再适用于预生成的选项卡..请帮助--(python 2.7)
#!/usr/bin/env python
import Tkinter
from Tkinter import *
import tkMessageBox
import ttk
root = Tkinter.Tk()
root.minsize(300,300)
root.geometry("1000x700")
body=ttk.Notebook(root,width=1000,height=650,)
tabs={'ky':1}
def generate_tabs(tab,name):
tab=Tkinter.Frame(body)
entry=Entry(tab).pack(side=TOP)
def alert(event):
tkMessageBox.showinfo('alert1','FocusOut event is working for '+name)
def printing(event):
print event.keysym+' for '+name
root.bind("<Key>",printing)
tab.bind_class('Entry',"<FocusOut>",alert)
body.add(tab,text=name)
def start_generating():
if tabs['ky']==4:pass
elif tabs['ky']==3: generate_tabs('tab4','tab4') ; tabs['ky']=4
elif tabs['ky']==2: generate_tabs('tab3','tab3') ; tabs['ky']=3
elif tabs['ky']==1: generate_tabs('tab2','tab2') ; tabs['ky']=2
else:pass
generate_tabs('tab1','tab1')
button=Button(root,text='generate',command=start_generating).pack(side=LEFT)
body.pack(side=TOP)
root.mainloop()