When using 'app' from a .kv file, AttributeError: 'NoneType' object has no attribute 'bind'
See original GitHub issueLike the title says, any reference to the main app from within the .kv file raises AttributeError: 'NoneType' object has no attribute 'bind'
Here’s a sample of my code:
#:kivy 1.9.0
<LoginScreen>:
GridLayout:
rows: 2
Label:
text: 'Login:'
GridLayout:
cols: 2
Label:
text: 'Username:'
TextInput:
multiline: False
text: app.getUsername()
Label:
text: 'Password:'
TextInput:
multiline: False
password: True
class TestApp(App):
def getUsername():
return 'asdf'
def build(self):
return sm
and the traceback:
[INFO ] [Logger ] Record log in /home/james/.kivy/logs/kivy_15-05-25_20.txt
[INFO ] [Kivy ] v1.9.0
[INFO ] [Python ] v3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2]
[INFO ] [Factory ] 173 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [OSC ] using <multiprocessing> for socket
[INFO ] [Window ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO ] [GL ] OpenGL version <b'3.0 Mesa 10.1.3'>
[INFO ] [GL ] OpenGL vendor <b'X.Org'>
[INFO ] [GL ] OpenGL renderer <b'Gallium 0.4 on AMD CAICOS'>
[INFO ] [GL ] OpenGL parsed version: 3, 0
[INFO ] [GL ] Shading version <b'1.30'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 1649, in create_handler
return eval(value, idmap)
File "test.kv", line 14, in <module>
text: app.getUsername()
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 857, in __getattribute__
object.__getattribute__(self, '_ensure_app')()
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 852, in _ensure_app
app.bind(on_stop=lambda instance:
AttributeError: 'NoneType' object has no attribute 'bind'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 2011, in _apply_rule
value, rule, rctx['ids'])
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 1654, in create_handler
cause=tb)
kivy.lang.BuilderException: Parser: File "test.kv", line 14:
...
12: TextInput:
13: multiline: False
>> 14: text: app.getUsername()
15: Label:
16: text: 'Password:'
...
AttributeError: 'NoneType' object has no attribute 'bind'
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 1649, in create_handler
return eval(value, idmap)
File "test.kv", line 14, in <module>
text: app.getUsername()
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 857, in __getattribute__
object.__getattribute__(self, '_ensure_app')()
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 852, in _ensure_app
app.bind(on_stop=lambda instance:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./main.py", line 20, in <module>
sm.add_widget(LoginScreen(name='login'))
File "/usr/lib/python3/dist-packages/kivy/uix/relativelayout.py", line 255, in __init__
super(RelativeLayout, self).__init__(**kw)
File "/usr/lib/python3/dist-packages/kivy/uix/floatlayout.py", line 66, in __init__
super(FloatLayout, self).__init__(**kwargs)
File "/usr/lib/python3/dist-packages/kivy/uix/layout.py", line 66, in __init__
super(Layout, self).__init__(**kwargs)
File "/usr/lib/python3/dist-packages/kivy/uix/widget.py", line 271, in __init__
Builder.apply(self)
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 1872, in apply
self._apply_rule(widget, rule, rule)
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 2018, in _apply_rule
e), cause=tb)
kivy.lang.BuilderException: Parser: File "test.kv", line 14:
...
12: TextInput:
13: multiline: False
>> 14: text: app.getUsername()
15: Label:
16: text: 'Password:'
...
BuilderException: Parser: File "test.kv", line 14:
...
12: TextInput:
13: multiline: False
>> 14: text: app.getUsername()
15: Label:
16: text: 'Password:'
...
AttributeError: 'NoneType' object has no attribute 'bind'
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 1649, in create_handler
return eval(value, idmap)
File "test.kv", line 14, in <module>
text: app.getUsername()
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 857, in __getattribute__
object.__getattribute__(self, '_ensure_app')()
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 852, in _ensure_app
app.bind(on_stop=lambda instance:
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 2011, in _apply_rule
value, rule, rctx['ids'])
File "/usr/lib/python3/dist-packages/kivy/lang.py", line 1654, in create_handler
cause=tb)
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 8 years ago
- Comments:5
Top Results From Across the Web
Kivy returns "AttributeError: 'NoneType' object has no attribute ...
I'm trying to create a screen that displays an image file whose path is stored in a ListProperty. I ...
Read more >AttributeError: 'NoneType' object has no attribute 'bind'
I suspect the problem is the conversion of the list property into a string. Looks like you are doing all operations with strings,...
Read more >[Kivy] AttributeError: 'NoneType' object has no attribute 'bind'
I want to include the variable named [show_text] into my [Label] , [text] at the [main. kv].
Read more >Python Kivy AttributeError: 'NoneType' object has no attribute ...
I am trying to write make a Calculator GUI with Kivy. This is the code: experiment.py from kivy.app import App from kivy.uix.boxlayout import...
Read more >AttributeError: 'NoneType' object has no attribute 'get_screen'
How to go fix - AttributeError: 'NoneType' object has no ... from kivy.app import App from kivy.lang import Builder from ... my.kv file...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In lieu of
app.getUsername()
, I also tried:str(7)
(succeeded)repr(type(self))
(succeeded)repr(type(app))
(succeeded)repr(type(repr))
(succeeded)repr(type(app.getUsername))
(failed)Fixed using variable instead of reference