TK-grid problem, please help

Ray ruiligc at NOSPAM.earthlink.net
Sat Apr 21 00:41:35 EDT 2007


hi, I have a question about how to use .grid_forget (in python/TK)

I need to work on grid repeatly. everytime when a button is pressed,
the rows of grid is different. such like, first time, it generate 10 
rows of data.
2nd time, it maybe only 5 rows. so I need a way to RESET the grid data
every time. how can I do it? by grid_forger()?, then would anyone can 
help on
how to use grid_forget()
the sample code as following:

#####begin of program###############

from Tkinter import *
def mygrid(text):
     ######## how to use grid_forget() to clean the grid??###########
     rows = []
     count=int(text)
     for i in range(count):
         cols = []
         for j in range(4):
             e = Entry(frame3, relief=RIDGE)
             e.grid(row=i, column=j, sticky=NSEW)
             e.insert(END, '%d.%d' % (i, j))
             cols.append(e)
             rows.append(cols)


root=Tk()

frame1=Frame(root, width=150, height=100)
frame1.pack()

text=Entry(frame1)
text.pack(side=LEFT)

button=Button(frame1, text='generate grid', command=(lambda: 
mygrid(text.get())))

button.pack()

frame2=Frame(root, width=150, height=100)
frame2.pack()

button2=Button(frame2, text='exit', command=root.quit)
button2.pack()

frame3=Frame(root, width=150, height=300)
frame3.pack()

root.mainloop()

#####end of program###############



More information about the Python-list mailing list