<legend id='LrzqS'><style id='LrzqS'><dir id='LrzqS'><q id='LrzqS'></q></dir></style></legend>
    <tfoot id='LrzqS'></tfoot>

    1. <small id='LrzqS'></small><noframes id='LrzqS'>

          <bdo id='LrzqS'></bdo><ul id='LrzqS'></ul>
        <i id='LrzqS'><tr id='LrzqS'><dt id='LrzqS'><q id='LrzqS'><span id='LrzqS'><b id='LrzqS'><form id='LrzqS'><ins id='LrzqS'></ins><ul id='LrzqS'></ul><sub id='LrzqS'></sub></form><legend id='LrzqS'></legend><bdo id='LrzqS'><pre id='LrzqS'><center id='LrzqS'></center></pre></bdo></b><th id='LrzqS'></th></span></q></dt></tr></i><div id='LrzqS'><tfoot id='LrzqS'></tfoot><dl id='LrzqS'><fieldset id='LrzqS'></fieldset></dl></div>

        如何通过按钮关闭 Kivy 弹出窗口?

        How to dismiss the Kivy pop-up via a Button?(如何通过按钮关闭 Kivy 弹出窗口?)

      1. <legend id='CFOAN'><style id='CFOAN'><dir id='CFOAN'><q id='CFOAN'></q></dir></style></legend>

            <i id='CFOAN'><tr id='CFOAN'><dt id='CFOAN'><q id='CFOAN'><span id='CFOAN'><b id='CFOAN'><form id='CFOAN'><ins id='CFOAN'></ins><ul id='CFOAN'></ul><sub id='CFOAN'></sub></form><legend id='CFOAN'></legend><bdo id='CFOAN'><pre id='CFOAN'><center id='CFOAN'></center></pre></bdo></b><th id='CFOAN'></th></span></q></dt></tr></i><div id='CFOAN'><tfoot id='CFOAN'></tfoot><dl id='CFOAN'><fieldset id='CFOAN'></fieldset></dl></div>
          1. <small id='CFOAN'></small><noframes id='CFOAN'>

            • <bdo id='CFOAN'></bdo><ul id='CFOAN'></ul>
                <tbody id='CFOAN'></tbody>
            • <tfoot id='CFOAN'></tfoot>

                  本文介绍了如何通过按钮关闭 Kivy 弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个使用 Kivy 创建的弹出窗口,其中包含 2 个按钮.用户可以通过在弹出区域外按下 (auto_dismiss = True) 或单击否"按钮来关闭弹出窗口.选择是"按钮,将退出整个应用程序.

                  请看相关代码:

                  类 ExitApp(App):def exit_confirmation(self):# popup 只能有一个 Widget.这可以通过添加 BoxLayout 来解决self.box_popup = BoxLayout(orientation = 'horizontal')self.box_popup.add_widget(Label(text = "真的退出?"))self.box_popup.add_widget(按钮(文字=是",on_press = ExitApp.exit,size_hint = (0.215, 0.075)))self.box_popup.add_widget(按钮(文字=否",on_press = self.popup_exit.dismiss,size_hint=(0.215, 0.075)))self.popup_exit = Popup(title = "退出",内容 = self.box_popup,size_hint = (0.4, 0.4),auto_dismiss = 真)self.popup_exit.open()def 退出(自我):App.get_running_app().stop()

                  现在的问题在于按下否"按钮.按下该按钮时,代码将退出并出现以下错误:

                  <块引用>

                   on_press = self.popup_exit.dismiss,

                  AttributeError: 'Button' 对象没有属性 'popup_exit'

                  知道如何尽可能轻松地解决此问题吗?

                  解决方案

                  你可以通过一个惰性函数来解决这个问题

                  on_press = lambda *args: self.popup_exit.dismiss()

                  这样,仅在按下按钮且 popup_exit 已就位时才会进行查找...

                  I have a pop-up created with Kivy, which contains 2 buttons. User can dismiss the pop-up by pressing outside of the pop-up area (auto_dismiss = True), or by clicking the "No" button. Selecting the "Yes" button, will exit the whole application.

                  Please see relevant code:

                  class ExitApp(App):
                  
                  def exit_confirmation(self):
                  
                      # popup can only have one Widget.  This can be fixed by adding a BoxLayout
                  
                      self.box_popup = BoxLayout(orientation = 'horizontal')
                  
                      self.box_popup.add_widget(Label(text = "Really exit?"))
                  
                      self.box_popup.add_widget(Button(
                          text = "Yes",
                          on_press = ExitApp.exit,
                          size_hint = (0.215, 0.075)))
                  
                      self.box_popup.add_widget(Button(
                          text = "No",
                          on_press = self.popup_exit.dismiss,
                          size_hint=(0.215, 0.075)))
                  
                      self.popup_exit = Popup(title = "Exit",
                          content = self.box_popup,
                          size_hint = (0.4, 0.4),
                          auto_dismiss = True)
                  
                      self.popup_exit.open()
                  
                  def exit(self):
                  
                      App.get_running_app().stop()
                  

                  The problem now lays with pressing the "No" button. When that is pressed, the code exits with this error:

                   on_press = self.popup_exit.dismiss,
                  

                  AttributeError: 'Button' object has no attribute 'popup_exit'

                  Any idea how I can fix this as easily as possible?

                  解决方案

                  You can solve this issue by a lazy function

                  on_press = lambda *args: self.popup_exit.dismiss()
                  

                  This way, the lookup will occur only when the button is pressed and popup_exit is already in place...

                  这篇关于如何通过按钮关闭 Kivy 弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)
                • <tfoot id='0SkQa'></tfoot><legend id='0SkQa'><style id='0SkQa'><dir id='0SkQa'><q id='0SkQa'></q></dir></style></legend>
                    <tbody id='0SkQa'></tbody>

                  <i id='0SkQa'><tr id='0SkQa'><dt id='0SkQa'><q id='0SkQa'><span id='0SkQa'><b id='0SkQa'><form id='0SkQa'><ins id='0SkQa'></ins><ul id='0SkQa'></ul><sub id='0SkQa'></sub></form><legend id='0SkQa'></legend><bdo id='0SkQa'><pre id='0SkQa'><center id='0SkQa'></center></pre></bdo></b><th id='0SkQa'></th></span></q></dt></tr></i><div id='0SkQa'><tfoot id='0SkQa'></tfoot><dl id='0SkQa'><fieldset id='0SkQa'></fieldset></dl></div>

                        <small id='0SkQa'></small><noframes id='0SkQa'>

                          • <bdo id='0SkQa'></bdo><ul id='0SkQa'></ul>