【发布时间】:2021-06-02 08:30:38
【问题描述】:
我正在研究 python,只是在做一些小游戏,但我被困住了,因为我找不到关于这个主题的任何信息。
我有 2 个按钮,并且希望在两个按钮中的任何一个单击时都隐藏它们。有没有办法做到这一点?
这是我在 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()
这里也是类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()
【问题讨论】:
-
您将按钮名称设为全局并相应隐藏
-
@Sujay 如果他们的名字变成全球性的,我该如何隐藏他们?
-
检查答案并相应替换