How to make simple menu in kivy?

Make a simple menu bar in Kivy (Python)

  • I am currently learning how to use Kivy to make a desktop Python GUI. I am trying to make a simple menu bar at the top of the application. This should look like something like that : I have tried to use the ActionBar as shown in the http://kivy.org/docs/examples/gen__demo__showcase__main__py.html. So here is my code : #!/usr/bin/env python3 from kivy.app import App class MenuApp(App): def button1(self): print("Button 1 triggered") if __name__ == '__main__': MenuApp().run() And file menu.kv : #:kivy 1.0.9 BoxLayout: orientation: "vertical" ActionBar: ActionView: ActionButton: text: "Button 1" on_release: app.button1() Button: text: "Nothing" background_color: 1, 1, 1, 0.6 background_normal: "" But I have the following error : [INFO ] [Logger ] Record log in /home/matthieu/.kivy/logs/kivy_15-06-29_19.txt [INFO ] [Kivy ] v1.9.0 [INFO ] [Python ] v3.4.0 (default, Jun 19 2015, 14:20:21) [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 ] [OSC ] using <multiprocessing> for socket [INFO ] [Window ] Provider: sdl2(['window_egl_rpi'] ignored) [INFO ] [GL ] OpenGL version <b'3.0 Mesa 10.3.2'> [INFO ] [GL ] OpenGL vendor <b'X.Org'> [INFO ] [GL ] OpenGL renderer <b'Gallium 0.4 on AMD OLAND'> [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 [INFO ] [Text ] Provider: sdl2 [INFO ] [Base ] Start application main loop [INFO ] [GL ] NPOT texture support is available [INFO ] [Base ] Leaving application in progress... Traceback (most recent call last): File "menuBar2/menuBar.py", line 14, in <module> MenuApp().run() File "/usr/lib/python3/dist-packages/kivy/app.py", line 824, in run runTouchApp() File "/usr/lib/python3/dist-packages/kivy/base.py", line 487, in runTouchApp EventLoop.window.mainloop() File "/usr/lib/python3/dist-packages/kivy/core/window/window_sdl2.py", line 539, in mainloop self._mainloop() File "/usr/lib/python3/dist-packages/kivy/core/window/window_sdl2.py", line 300, in _mainloop EventLoop.idle() File "/usr/lib/python3/dist-packages/kivy/base.py", line 327, in idle Clock.tick() File "/usr/lib/python3/dist-packages/kivy/clock.py", line 483, in tick self._process_events() File "/usr/lib/python3/dist-packages/kivy/clock.py", line 615, in _process_events event.tick(self._last_tick, remove) File "/usr/lib/python3/dist-packages/kivy/clock.py", line 374, in tick ret = callback(self._dt) File "/usr/lib/python3/dist-packages/kivy/uix/boxlayout.py", line 174, in do_layout c.width = w File "properties.pyx", line 397, in kivy.properties.Property.__set__ (kivy/properties.c:4543) File "properties.pyx", line 429, in kivy.properties.Property.set (kivy/properties.c:5025) File "properties.pyx", line 484, in kivy.properties.Property.dispatch (kivy/properties.c:5641) File "_event.pyx", line 1168, in kivy._event.EventObservers.dispatch (kivy/_event.c:11690) File "_event.pyx", line 1074, in kivy._event.EventObservers._dispatch (kivy/_event.c:11029) File "/usr/lib/python3/dist-packages/kivy/uix/actionbar.py", line 568, in on_width self._layout_all() File "/usr/lib/python3/dist-packages/kivy/uix/actionbar.py", line 453, in _layout_all super_add(self.action_previous) File "/usr/lib/python3/dist-packages/kivy/uix/boxlayout.py", line 210, in add_widget widget.bind( AttributeError: 'NoneType' object has no attribute 'bind' Does someone know what I am doing wrong ?

  • Answer:

    try it like this , i think it should work ActionBar: ActionPrevious: ActionView: ActionButton: text: "Button 1" on_release: app.button1()

Matthieu Pizenberg at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.