1

I'm using Python 3.5.

I want to make a button invisible and I found it:

import tkinter
from tkinter import *

def hide_btn():
    def hide_me(event):
        event.widget.pack_forget()

    root = Tk()

    hiddenbtn = Button(root, text = 'Hello World')
    hiddenbtn.place(x = 0, y = 0)

    hiddenbtn.bind('<Button-1>', hide_me)
    hiddenbtn.pack()

    root.mainloop()

hide_btn()

It works well, but I want to make the button clicked.

Is there any way to make it clicked?

6
  • What do you mean by I want to make the button clicked.? Commented Jun 27, 2018 at 10:03
  • Well, when you run the program, the button is shown. And when you click the button, the button become invisible. I want to make the button invisible from the first time. So I want to make the button clicked. Commented Jun 27, 2018 at 10:05
  • Yes. Exactly right. Commented Jun 27, 2018 at 10:10
  • Well, when I change my code, AttributeError: 'Button' object has no attribute 'lbl' comes out. Commented Jun 27, 2018 at 10:14
  • If you don't want the widget shown, just don't place/pack it until you do want it to be shown? (Also don't use both place and pack for widgets in the same master, let alone for one widget. Pick one.) Commented Jun 27, 2018 at 10:31

1 Answer 1

1

In that case you do not need to bind the button, you can simple rely on place_forget() to do the job. This is what I mean:

import tkinter
from tkinter import *

def hide_btn():       

    root = Tk()

    hiddenbtn = Button(root, text = 'Hello World')
    hiddenbtn.place(x = 0, y = 0)
    hiddenbtn.place_forget()      

    root.mainloop()

hide_btn()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.