Hello All:
I finally figured out what was wrong with my code before, with regard to creating new nodes (please see code below). My difficulty now is understanding how to work with focus.
I am able to generate nodes and I am able to identify them by their position. Now, I am trying to identify nodes that have focus. But, perhaps my thinking is wrong? Essentially, I am trying to identify the node(s) that the user has selected, so that only certain events can occur when those nodes are highlighted/selected/have focus - ?. For example, if a parent is 'selected' or 'has focus', the end-user can create other parents AND/OR additional children, but if a child is 'selected' or 'has focus', only additional children can be created. I have tried the 'focus' function in varying combinations, but I'm always returning 'None' or an instance-error.
Any suggestions here are quite welcome. I am beginning to understand things a bit better now, but 'global'-? BWidget functions are not one of these things.
Thank you and Best Regards,
Chris Nethery
############ file tree_example.py ##############################
import Tkinter as tk
import bwidget as bw
import string
import Tkinter as tk
import bwidget as bw
import string
class DirTree(tk.Frame):
def __init__(self, master, *args, **kw):
tk.Frame.__init__(self, master)
treeFrame = tk.Frame(master)
treeFrame.pack(side=tk.TOP)
self.tree_Instance = tree_Instance = bw.Tree(treeFrame, padx=60, opencmd=self.open_node, closecmd=self.close_node, *args, **kw)
tree_Instance.pack(fill='both', expand=1)
tk.Frame.__init__(self, master)
treeFrame = tk.Frame(master)
treeFrame.pack(side=tk.TOP)
self.tree_Instance = tree_Instance = bw.Tree(treeFrame, padx=60, opencmd=self.open_node, closecmd=self.close_node, *args, **kw)
tree_Instance.pack(fill='both', expand=1)
self.tree_icon = tk.PhotoImage(file=tree_icon.gif')
self.parent_icon = tk.PhotoImage(file='parent_icon.gif')
self.child_icon = tk.PhotoImage(file='child_icon.gif')
self.node = tree_Instance.insert('end', 'root', text='Sample Tree', image=self.tree_icon, drawcross='allways', data='')
tree_Instance.opentree(self.node, recurse=0)
buttonFrame = tk.Frame(master)
buttonFrame.pack(side=tk.BOTTOM)
self.creat_Nodes_Button = tk.Button(buttonFrame, text='Create Nodes', command=self.create_nodes, relief=tk.GROOVE)
self.creat_Nodes_Button.pack()
def close_node(self, node):
self.tree_Instance.itemconfigure(node)
self.parent_icon = tk.PhotoImage(file='parent_icon.gif')
self.child_icon = tk.PhotoImage(file='child_icon.gif')
self.node = tree_Instance.insert('end', 'root', text='Sample Tree', image=self.tree_icon, drawcross='allways', data='')
tree_Instance.opentree(self.node, recurse=0)
buttonFrame = tk.Frame(master)
buttonFrame.pack(side=tk.BOTTOM)
self.creat_Nodes_Button = tk.Button(buttonFrame, text='Create Nodes', command=self.create_nodes, relief=tk.GROOVE)
self.creat_Nodes_Button.pack()
def close_node(self, node):
self.tree_Instance.itemconfigure(node)
def open_node(self, node):
path = self.tree_Instance.opentree(node, recurse=1)
path = self.tree_Instance.opentree(node, recurse=1)
def create_nodes(self):
parent_0 = self.tree_Instance.insert(0, 0, text='1st Parent', image=self.parent_icon, drawcross='allways')
child_0_0 = self.tree_Instance.insert(0, parent_0, text='1st Child', image=self.child_icon, drawcross='allways')
child_0_1 = self.tree_Instance.insert(1, parent_0, text='2nd Child', image=self.child_icon, drawcross='allways')
child_0_2 = self.tree_Instance.insert(2, parent_0, text='3rd Child', image=self.child_icon, drawcross='allways')
parent_1 = self.tree_Instance.insert(1, 0, text='2nd Parent', image=self.parent_icon, drawcross='allways')
child_1_0 = self.tree_Instance.insert(0, parent_1, text='1st Child', image=self.child_icon, drawcross='allways')
child_1_1 = self.tree_Instance.insert(2, parent_1, text='2nd Child', image=self.child_icon, drawcross='allways')
child_1_2 = self.tree_Instance.insert(3, pare! nt_1, text='3rd Child', image=self.child_icon, drawcross='allways')
widget_List = [
parent_0,
child_0_0,
child_0_1,
child_0_2,
parent_1,
child_1_0,
child_1_1,
child_1_2,
]
for w in widget_List:
print self.tree_Instance.index(w)
parent_0 = self.tree_Instance.insert(0, 0, text='1st Parent', image=self.parent_icon, drawcross='allways')
child_0_0 = self.tree_Instance.insert(0, parent_0, text='1st Child', image=self.child_icon, drawcross='allways')
child_0_1 = self.tree_Instance.insert(1, parent_0, text='2nd Child', image=self.child_icon, drawcross='allways')
child_0_2 = self.tree_Instance.insert(2, parent_0, text='3rd Child', image=self.child_icon, drawcross='allways')
parent_1 = self.tree_Instance.insert(1, 0, text='2nd Parent', image=self.parent_icon, drawcross='allways')
child_1_0 = self.tree_Instance.insert(0, parent_1, text='1st Child', image=self.child_icon, drawcross='allways')
child_1_1 = self.tree_Instance.insert(2, parent_1, text='2nd Child', image=self.child_icon, drawcross='allways')
child_1_2 = self.tree_Instance.insert(3, pare! nt_1, text='3rd Child', image=self.child_icon, drawcross='allways')
widget_List = [
parent_0,
child_0_0,
child_0_1,
child_0_2,
parent_1,
child_1_0,
child_1_1,
child_1_2,
]
for w in widget_List:
print self.tree_Instance.index(w)
print 'But I cannot seem to "find" focus. : ) Focus = ' + str(self.tree_Instance.focus())
def test():
r = tk.Tk()
t = DirTree(r, bg='white', selectbackground='blue4', selectforeground='white', deltax=60, deltay=45, width=50)
t.pack(fill='both', expand=1)
r.mainloop()
r = tk.Tk()
t = DirTree(r, bg='white', selectbackground='blue4', selectforeground='white', deltax=60, deltay=45, width=50)
t.pack(fill='both', expand=1)
r.mainloop()
if __name__== '__main__':
test()
##############################################################
test()
##############################################################
_______________________________________________ Tkinter-discuss mailing list [email protected] http://mail.python.org/mailman/listinfo/tkinter-discuss
