everybody! I'm just learning python GUI and I can't figure out what am I doing wrong. I'm trying to draw a tree of buttons. I've created a first button in a frame then when I click it, I expect two more frames to be placed in a parent frame and two more buttons place in these new frames and so on. But when I'm clicking the button on a second iteration it adds new frames not to the button's frame but in the LAST FRAME that was created.
from Tkinter import *
class my_class():
def __init__(self,frame):
self.frame=frame
def create_frames(self):
Frames=[]
p=2
for k in range(p):
New_frame=Frame(self.frame, highlightbackground="green", highlightcolor="green", highlightthickness=1,
width=100, height=100, bd=0)
New_frame.pack(side=LEFT)
Frames.append(New_frame)
obj=my_class(Frames[k])
but=Button(obj.frame, text='but', command=lambda:obj.create_frames())
but.pack()
my_app=Tk()
obj=my_class(my_app)
but=Button(my_app,text='butt',command=lambda:obj.create_frames())
but.pack()
my_app.mainloop()