How To Make Instances Of Event For Every Single Tab On Multi Tab Gui Tkinter( Notebook Widget)
this is my code.. and i need the event binding to work for all tabs the same time..the problem is when generate new tab the event binding will be related to the last generated tab
Solution 1:
I use class MyTab to create new tab with own function alert (called when you focus out entry) and printing (called when you type in entry).
I use print
in place of tkMessageBox
because messagebox focuse out entry on new selected tab (when you change tab) so you don't see messagebox from previous tab, but from current tab.
#!/usr/bin/env pythonfrom Tkinter import *
import tkMessageBox
import ttk
#---------------------------------------------------------------------classMyTab(Frame):
def__init__(self, root, name):
Frame.__init__(self, root)
self.root = root
self.name = name
self.entry = Entry(self)
self.entry.pack(side=TOP)
self.entry.bind('<FocusOut>', self.alert)
self.entry.bind('<Key>', self.printing)
#-------------------------------defalert(self, event):
print'FocusOut event is working for ' + self.name + ' value: ' + self.entry.get()
#tkMessageBox.showinfo('alert', 'FocusOut event is working for ' + self.name + ' value: ' + self.entry.get())#-------------------------------defprinting(self, event):
print event.keysym + ' for ' + self.name
#---------------------------------------------------------------------classApplication():
def__init__(self):
self.tabs = {'ky':1}
self.root = Tk()
self.root.minsize(300, 300)
self.root.geometry("1000x700")
self.notebook = ttk.Notebook(self.root, width=1000, height=650)
# self.all_tabs = []
self.addTab('tab1')
self.button = Button(self.root, text='generate', command=self.start_generating).pack(side=BOTTOM)
self.notebook.pack(side=TOP)
#-------------------------------defaddTab(self, name):
tab = MyTab(self.notebook, name)
self.notebook.add(tab, text=name)
# self.all_tabs.append(tab)#-------------------------------defstart_generating(self):
if self.tabs['ky'] < 4:
self.tabs['ky'] += 1
self.addTab('tab'+ str(self.tabs['ky']))
#-------------------------------defrun(self):
self.root.mainloop()
#----------------------------------------------------------------------
Application().run()
Post a Comment for "How To Make Instances Of Event For Every Single Tab On Multi Tab Gui Tkinter( Notebook Widget)"