Question

I am trying to create a column of buttons which when they are pressed, the grid that down a row show pop up another two buttons.

for i in tlist:
    opl.append(Tk.Button(self.frame, width = 12 , text=i[3],command = lambda:self.pressedop(i[2], a)))
    opl[a].grid(row=a, column=0, columnspan=2)
    a = a + 1

That successfully create a column of buttons, with text(i[3]) correctly shown, but when a button is pressed, i[2] will be last button's info, and a will be last button's row +1.

Is there a way which I can pass the i[2] and it's own grid_info down?

Was it helpful?

Solution

I don't understand your question, but you can use widget.grid_forget() to remove a widget from the geometry manager. If you then want it in a different row, just widget.grid() with the new row and column. A simple example

try:
    import Tkinter as tk     ## Python 2.x
except ImportError:
    import tkinter as tk     ## Python 3.x

from functools import partial

opl = []
top = tk.Tk()

def move_it(num):
    for ctr in range(num, 5):
        opl[ctr].grid_forget()   
        opl[ctr].grid(row=6, column=ctr)

for but_num in range(5):
    opl.append(tk.Button(top, width = 12 , text=str(but_num),
               command = partial(move_it, but_num)))
    opl[-1].grid(row=but_num, column=0, columnspan=2)

top.mainloop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top