左侧的菜单设置

时间:2017-11-02 11:56:51

标签: python-2.7 kivy kivy-language

menu.py

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()

set menu in left side

如何设置菜单左侧。现在这些菜单右侧。如何设置左侧而不是示例应用程序。之后在菜单(第二行)下添加小图标添加。

第一行 - 文件编辑工具(带子菜单)
第二行 - icon1 icon2 icon3

1 个答案:

答案 0 :(得分:1)

我不认为可以在操作栏上切换侧面,至少在不进行大量更改的情况下是这样。因此,这是一个左侧有按钮的解决方案。它不那么美丽。你需要自己调整尺寸和背景颜色。

enter image description here

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.dropdown import DropDown
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder


class CustDrop(DropDown):
    def __init__(self, **kwargs):
        super(CustDrop, self).__init__( **kwargs)
        self.select('')


kv_str = Builder.load_string('''


BoxLayout:
    orientation: 'vertical'
    BoxLayout:
        canvas.before:
            Rectangle:
                pos: self.pos
                size: self.size
            Color:
                rgb: (1,1,1)
        size_hint_y:1
        Button:
            text: 'File'
        Button:
            text: 'Edit'


        Button:
            id: btn
            text: 'Tools'
            on_release: dropdown.open(self)
            #size_hint_y: None
            #height: '48dp'  


        CustDrop:

            id: dropdown

            Button:
                text: 'First Item'
                size_hint_y: None
                height: '48dp'
                on_release: dropdown.select('')
                on_release: print('First Item pressed')

            Button:
                text: 'First Item'
                size_hint_y: None
                height: '48dp'
                on_release: dropdown.select('')


            Button:
                text: 'Third Item'
                size_hint_y: None
                height: '48dp'
                on_release: dropdown.select('')

        Label:
            size_hint_x: 4

    Label:
        size_hint_y: 9

''')


class ExampleApp(App):
    def build(self):
        return kv_str

if __name__ =='__main__':
    ExampleApp().run()

我通过将空字符串传递给select方法有点欺骗。可能DropDown最初并不打算以这种方式使用。

相关问题