0

I want to hide or show label, button and other stuff in tkinter window, here is simple code:

import tkinter as tk

window = tk.Tk()
window.title("window")

label1 = tk.Label(text="Hello")
label1.grid(column=0, row=0)

label2 = tk.Label(text="Goodbye")
label2.grid(column=0, row=0)

while True:
    window.update()

So, for example, I want to hide or show label. I know that in this case I can just change text (label['text'] = "text"), but I need ways to solve problems like this:

import tkinter as tk

window = tk.Tk()
window.title("window")

def start():
    pass
    # Here must be way to hide button1 and show button2

def exit():
    exit(0)

button1 = tk.Button(text="Start", width=20, height=2, command=start)
button1.grid(column=0, row=0)

button2 = tk.Button(text="Quit", width=20, height=2, command=exit)   # This button must be hidden
button2.grid(column=0, row=0)

while True:
    window.update()

So, in this case, I need to hide and show two buttons. Any ideas?

  • Take a look at this SO question, and the comments about raise and lower of the widgets to hide them. https://stackoverflow.com/questions/3819354/in-tkinter-is-there-any-way-to-make-a-widget-invisible – Rob Py Dec 21 '21 at 07:58

0 Answers0