Search code examples
pythonkivykivy-language

Create a dropdown menu at the top of the window


How to create a dropdown menu at the top of the window (like "File", "Edit", and "Tools") in Kivy?


Solution

  • How about using ActionBar

    enter image description here

    from kivy.app import App
    from kivy.lang import Builder
    
    kv_str = Builder.load_string('''
    ActionBar:
        pos_hint: {'top':1}
        ActionView:
            use_separator: True
            ActionPrevious:
                title: 'Example App'
                with_previous: False
            ActionButton:
                text: 'File'
            ActionButton:
                text: 'Edit'
            ActionGroup:
                text: 'Tools' 
                mode: 'spinner'
                ActionButton:
                    text: 'Tool1'
                ActionButton:
                    text: 'Tool2'
                ActionButton:
                    text: 'Tool3'
                ActionButton:
                    text: 'Tool4'
    ''')
    
    
    class ExampleApp(App):
        def build(self):
            return kv_str
    
    if __name__ =='__main__':
        ExampleApp().run()