TankorSmash

List Focus for SO

Jun 30th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import Tkinter, ttk
  2.  
  3. class tv(ttk.Treeview):
  4.     #----------------------------------------------------------------------
  5.     def __init__(self, master, *args, **kwargs):
  6.         """"""
  7.         ttk.Treeview.__init__(self, master, *args, **kwargs)
  8.        
  9.         print 'root got focus?', master.focus_get()
  10.         self.items = [ self.insert( '', 'end',
  11.                                 text = str( i ) ) for i in range( 10 ) ]
  12.        
  13.         self['takefocus']= True
  14.        
  15.         self.selection_set(self.items[5])
  16.         self.pack( fill = Tkinter.BOTH, expand = 1 )
  17.        
  18.         self.after(3000, self.focus_set)
  19.         print 'just set focus', self.focus_set()
  20.         print 'Treeview Focus set focus set? :', self.focus_get()
  21.         print 'focus displayof', self.focus_displayof()
  22.        
  23.         #print 'selfs id', self.info()
  24.        
  25.         master.focus_set()
  26.         print 'root got focus?', master.focus_get()
  27.        
  28.         self.bind('<Key>', self.callback)
  29.        
  30.     def callback(self, e):
  31.        
  32.         self.selection_set(self.items[2])
  33.         print 'The TreeView Widget caught the key'
  34.        
  35. root = Tkinter.Tk()
  36. root.config(takefocus=1)
  37.  
  38. def callback(e):
  39.     print 'root caught key'
  40.    
  41. root.bind('<Key>', callback)
  42.  
  43. root.focus_set()
  44. root.focus()
  45.  
  46. list2 = tv(root)
  47.  
  48. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment