有没有办法隐藏所有现有按钮?

Is there a way to hide all existing buttons?

我正在学习 python 并且只是在做一些小游戏,但我被卡住了,因为我找不到关于这个主题的任何内容。

我有 2 个按钮,我希望它们都在单击其中一个时隐藏。有办法吗?

这是 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()

这里是按钮的主要启动和创建也在 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()

你可以替换函数

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 )

然后是这些函数

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()

使用

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

取决于您使用的几何管理器。