【问题标题】:Open a new widget, arrange buttons. Python, KIVY打开一个新的小部件,排列按钮。蟒蛇,基维
【发布时间】:2014-12-27 17:24:12
【问题描述】:

使用此代码,我想要做的是分组并显示几个按钮,并在按下每个按钮时打开一个应用程序。

PY 文件

class CustomPopup(popup):
    pass


class TestApp(App):

    def build(self):
    help_me_button = Button(text='HELP ME')
    help_me_button.bind(on_press=self.open_helpme)
    games_button = Button(text='GAMES')
    games_button.bind(on_press=self.open_games)

    buttons = BoxLayout(orientation='horizontal')
    buttons.add_widget(help_me_button)
    buttons.add_widget(game_button)


    return layout

def open_help_me(self, help_me):
    p = self.popup

    p = Popup(content=help_me,
              title='Help Me',
              size_hint=(0.8, 0.8))

        if p.content is not help_me:
            p.content = help_me
        p.open()
    else:
        super(HelpMeApp, self).display_helpme(HelpMe)

每次我运行程序时,它都会显示弹出窗口未定义或应用程序运行并立即关闭,谁能告诉我我做错了什么。我是编程新手。

【问题讨论】:

  • 你有什么问题?
  • 我做了这个问题。

标签: python kivy


【解决方案1】:

p = self.popup 不应该在那里。您尝试访问未定义的“self.popup” - 下一行您正在做正确的事情,您正在创建一个新的 Popup(通过编写 p = Popup(...) 完成)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-06
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    相关资源
    最近更新 更多