Hi,

I am looking for a little example of making a window visible or invisible.
I have a main window with 2 buttons (option1 and option2). If i press option one i open a new window with something else but i want that keep stored in a variable that i choosed option1 and want main window go invisible and then i can make it visible again when i select exit from option1 window

thanks in advance

Use the grid.forget() on the frame you want to hide and the .grid() to make the new frame visible. like what you see below.

frame1.grid(row = 0, column = 0)
        frame2.grid_forget()

Thank you very much.

But for a button? If i have 3 buttons, i want second button to be "invisible" and be visible only after i press button 1 ?

same would apply what i posted was just an example of how you could hide and show your buttons. Never tried hiding anything using pack but i tried the grid forget method and it worked.

This might give you a hint ...

''' tk_label_lift_lower.py
hide and show labels sharing the same grid position 
with lift and lower
'''

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    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, padx=10, pady=5)

button2 = tk.Button(root, text="Press to show label1", command=show1)
button2.grid(row=1, column=0)

# label1 and label2 share the same grid position
label1 = tk.Label(root, text=" now showing label1 ", bg='yellow')
label1.grid(row=2, column=0, pady=5)

label2 = tk.Label(root, text=" now showing label2 ", bg='green')
label2.grid(row=2, column=0, pady=5)

# at start this will put label2 below label1
label2.lower()

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.