This is one way to hide and show widgets that share the same grid ...
# hide and show labels sharing the same grid
import Tkinter as tk
def show2():
label1.lower()
label2.lift()
def show1():
label2.lower()
label1.lift()
root = tk.Tk()
button1 = tk.Button(root, text="Press to show label2", command=show2)
button1.grid(row=0, column=0)
button2 = tk.Button(root, text="Press to show label1", command=show1)
button2.grid(row=1, column=0)
label1 = tk.Label(root, text="text in label1", bg='yellow')
label1.grid(row=2, column=0)
label2 = tk.Label(root, text="text in label2", bg='green')
label2.grid(row=2, column=0)
# label1 and label2 share the same grid
# this will put label2 below label1
label2.lower()
root.mainloop()
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
Make the two labels the same width by adding for instance width=30 to the arguments.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417