Я пытаюсь открыть всплывающее окно после нажатия кнопки, используя python kivy, но получаю сообщение об ошибке
Вот мой код:
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.config import Config
Config.set("graphics", "resizable", 0)
Config.set("graphics", "width", 400)
Config.set("graphics", "height", 500)
class myLayout(BoxLayout):
def __init__(self, **kwargs):
super(myLayout, self).__init__(**kwargs)
btn = Button(text="Click")
btn.bind(on_press=self.clk)
self.add_widget(btn)
def clk(self, obj):
popup = Popup(content="I am popup")
return popup.open()
class ReminderApp(App):
def build(self):
mL = myLayout()
return mL
if __name__ == "__main__":
ReminderApp().run()
Это работает, если в clk
функция вместовсплывающее окно print
что-то, например:
def clk(self, obj):
print("Hello world")
Помогите мне, пожалуйста, я застрял
Вот сообщение об ошибке:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang/builder.py", line 619, in _apply_rule
setattr(widget_set, key, value)
File "kivy/weakproxy.pyx", line 33, in kivy.weakproxy.WeakProxy.__setattr__
File "kivy/properties.pyx", line 478, in kivy.properties.Property.__set__
File "kivy/properties.pyx", line 516, in kivy.properties.Property.set
File "kivy/properties.pyx", line 571, in kivy.properties.Property.dispatch
File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/popup.py", line 223, in on__container
self._container.add_widget(self.content)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/boxlayout.py", line 312, in add_widget
widget.fbind('pos_hint', self._trigger_layout)
AttributeError: 'str' object has no attribute 'fbind'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 40, in <module>
ReminderApp().run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/app.py", line 826, in run
runTouchApp()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/base.py", line 502, in runTouchApp
EventLoop.window.mainloop()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/core/window/window_sdl2.py", line 723, in mainloop
self._mainloop()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/core/window/window_sdl2.py", line 460, in _mainloop
EventLoop.idle()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/base.py", line 340, in idle
self.dispatch_input()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/base.py", line 325, in dispatch_input
post_dispatch_input(*pop(0))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/base.py", line 231, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/core/window/__init__.py", line 1352, in on_motion
self.dispatch('on_touch_down', me)
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/core/window/__init__.py", line 1368, in on_touch_down
if w.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/widget.py", line 460, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/behaviors/button.py", line 151, in on_touch_down
self.dispatch('on_press')
File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
File "main.py", line 25, in clk
popup = Popup(content="I am popup")
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/modalview.py", line 152, in __init__
super(ModalView, self).__init__(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/anchorlayout.py", line 68, in __init__
super(AnchorLayout, self).__init__(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/layout.py", line 76, in __init__
super(Layout, self).__init__(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/widget.py", line 348, in __init__
Builder.apply(self, ignored_consts=self._kwargs_applied_init)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang/builder.py", line 469, in apply
self._apply_rule(widget, rule, rule, ignored_consts=ignored_consts)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang/builder.py", line 630, in _apply_rule
e), cause=tb)
kivy.lang.builder.BuilderException: Parser: File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/data/style.kv", line 506:
...
504:# Popup widget
505:<Popup>:
>> 506: _container: container
507: GridLayout:
508: padding: '12dp'
...
AttributeError: 'str' object has no attribute 'fbind'
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang/builder.py", line 619, in _apply_rule
setattr(widget_set, key, value)
File "kivy/weakproxy.pyx", line 33, in kivy.weakproxy.WeakProxy.__setattr__
File "kivy/properties.pyx", line 478, in kivy.properties.Property.__set__
File "kivy/properties.pyx", line 516, in kivy.properties.Property.set
File "kivy/properties.pyx", line 571, in kivy.properties.Property.dispatch
File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/popup.py", line 223, in on__container
self._container.add_widget(self.content)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/boxlayout.py", line 312, in add_widget
widget.fbind('pos_hint', self._trigger_layout)
Exception ignored in: functools.partial(<function _widget_destructor at 0x102eaad08>, 23)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/widget.py", line 265, in _widget_destructor
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang/builder.py", line 760, in unbind_widget
File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__
AttributeError: 'weakref' object has no attribute 'cline_in_traceback'
Exception ignored in: functools.partial(<function _widget_destructor at 0x102eaad08>, 34)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/widget.py", line 265, in _widget_destructor
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang/builder.py", line 760, in unbind_widget
File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__
AttributeError: 'weakref' object has no attribute 'cline_in_traceback'
Exception ignored in: functools.partial(<function _widget_destructor at 0x102eaad08>, 39)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/uix/widget.py", line 265, in _widget_destructor
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/kivy/lang/builder.py", line 760, in unbind_widget
File "kivy/weakproxy.pyx", line 30, in kivy.weakproxy.WeakProxy.__getattr__
AttributeError: 'weakref' object has no attribute 'cline_in_traceback'