Nics Reyes
Nics Reyes

Reputation: 55

Is there a way to hide all existing buttons?

I'm studying python and just doing some small games and I'm stuck because I can't find anything about this topic.

I have 2 buttons and want both of them hide when any one of the two clicked. is there a way to do this?

here is my codes for the buttons inside the class RedRidingHood:

def p1Choice_a(self, event):
    print("You choose to run from the big wolf")
    event.widget.pack_forget()

def p1Choice_b(self, event):
    print("You choose to talk the big wolf")
    event.widget.pack_forget()

and here is the main start and creation of button also inside the class RedRidingHood:

def start(self):
    self.create_button_p1()

def create_button_p1(self, position):
    p1ca = Button(frame, text="A. Run from the big wolf")
    p1ca.bind('<Button-1>', self.p1Choice_a)
    p1ca.pack( side = LEFT )

    p1cb = Button(frame, text="B. Have a conversation with the big wolf")
    p1cb.bind('<Button-2>', self.p1Choice_b)
    p1cb.pack( side = RIGHT )


rrhStart = RedRidingHood()
rrhStart.start()

Upvotes: 0

Views: 104

Answers (2)

user15801675
user15801675

Reputation:

You could replace the functions

def create_button_p1(self, position):
    self.p1ca = Button(frame, text="A. Run from the big wolf")
    self.p1ca.bind('<Button-1>', self.p1Choice_a)
    self p1ca.pack( side = LEFT )

    self.p1cb = Button(frame, text="B. Have a conversation with the big wolf")
    self.p1cb.bind('<Button-2>', self.p1Choice_b)
    self.p1cb.pack( side = RIGHT )

And then these functions

def p1Choice_a(self, event):
    print("You choose to run from the big wolf")
    self.p1ca.pack_forget()
    self.p1cb.pack_forget()

def p1Choice_b(self, event):
    print("You choose to talk the big wolf")
    self.p1cb.pack_forget()
    self.p1ca.pack_forget()

Upvotes: 1

PCM
PCM

Reputation: 3011

Use

.pack_forget()
.grid_forget()
.place_forget()

depending on which geometry manager you are using.

Upvotes: 0

Related Questions