按钮不会工作(kivy)(python)

时间:2018-04-20 08:02:07

标签: python button kivy

有人可以向我解释为什么这个按钮不起作用吗?当我运行游戏时,按钮可见,但我无法按下它。

class game_widget(Widget):
def __init__(self, **kwargs):
    super(game_widget, self).__init__(**kwargs)
    with self.canvas:
        Color(*sky_color)
        Rectangle(pos=(0, 0), size=self.size)
    with self.canvas:
        Color(*grass_color)
        Rectangle(pos=(0,0), size=(800,75))
    with self.canvas:
        Label(text='Funky Chicken', font_size='50sp', pos=(360, 400))
    with self.canvas:
        self.main_menu_button = Button(text='Play', pos=(360, 200))
        self.main_menu_button.bind(on_press = self.main_menu_button_callback)

    layout = FloatLayout()
    layout.add_widget(self.main_menu_button)

def main_menu_button_callback(self, obj):
    click_sound.play()

class FunkyChickenApp(App):
    def build(self):
        return game_widget(size=Window.size)

显然,按钮似乎只是某种画布。工作示例:

self.main_menu_button = Button(text='Play', font_size=25, pos=(360, 200))
self.main_menu_button.bind(on_press=self.main_menu_button_callback)

    self.add_widget(self.main_menu_button)

def main_menu_button_callback(self, obj):
    click_sound.play()
    print("button working")`

0 个答案:

没有答案