How to hide a Widget?

Asked

Viewed 901 times

0

I need to know some way that by clicking on Button "hide" a widget (a Label for example) from my window, being possible to use it later; Using place in widget you wish to "hide" (Yes, MUST be the .place).

OBS: Forgive me for any fault in the creation of the question, or lack of clarity; any doubt that has been left by me, I am readily willing to clarify by way of the commentary.

OBS: Use python 3, and for GUI: Tkinter(If you haven’t made it clear through the tag).

Thank you in advance!

2 answers

2

Hello!

I started studying the module tkinter yesterday, unfortunately I have that same doubt. But I did that famous 'gambiarra' rsrs:

from tkinter import *

root = Tk()

texto = Label(root, text = 'Exemplo')
texto.place(x=200, y=200)

root.geometry('400x400')
root.mainloop()

Here was the example code, however, I want to "hide" the label "TEXT".

from tkinter import *

def esconder():
    texto.place(x=3000, y=3000) #Faz a label ir pra um lugar que não aparece na tela


root = Tk()

texto = Label(root, text = 'Exemplo')
botao = Button(root, text = 'Esconder', command = esconder)

texto.place(x=200, y=200)
botao.place(x=200, y=350)


root.geometry('400x400')
root.mainloop()

Explaining the code, the def esconder() received the "order" to play the texto to a place where it does not appear on the screen, making it "hidden".

If you want to reuse in the future, just state the:

texto.place(x=200, y=200)

That he goes back to where he was. I hope I helped.

0

Use the method place_forget()

from tkinter import *


def esconder():
    texto.place_forget()



root = Tk()

texto = Label(root, text = 'Exemplo')
texto.place(x=200, y=200)

bt = Button(root, text = 'Esconder', command = esconder)
bt.pack()


root.geometry('400x400')
root.mainloop()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.