Kivy不显示操作栏

时间:2018-08-27 03:17:57

标签: python python-3.x kivy kivy-language

我具有以下代码来创建操作栏:

Python代码:

from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.actionbar import ActionBar

Window.clearcolor = (1, 1, 1, 1)

class Menu(ActionBar):
    pass


class TestApp(App):

def build(self):
    return design


design = Builder.load_file('test.kv')

这是kv代码:

#: import ActionBar kivy.uix.actionbar

<Menu>:
    pos_hint: {'top': 1}
    ActionView:
        use_separator: True
        ActionPrevious:
            title: 'Action Bar'
            with_previous: False
        ActionButton:
            important: True
            text: 'Add'
        ActionButton:
            text: 'FAQ'
        ActionButton:
            text: 'Credits'

当我运行上面的代码时,它仅显示一个白色窗口并立即关闭。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

尝试一下:

from kivy.core.window import Window
from kivy.base import runTouchApp
from kivy.lang import Builder

Window.clearcolor = (1, 1, 1, 1)

runTouchApp(Builder.load_file('test.kv'))

test.kv:

ActionBar:
    pos_hint: {'top':1}
    ActionView:
        use_separator: True
        ActionPrevious:
            title: 'Action Bar'
            with_previous: False
        ActionOverflow:
        ActionButton:
            icon: 'atlas://data/images/defaulttheme/audio-volume-high'
        ActionButton:
            important: True
            text: 'Important'
        ActionButton:
            text: 'Btn2'
        ActionButton:
            text: 'Btn3'
        ActionButton:
            text: 'Btn4'
        ActionGroup:
            text: 'Group1'
            ActionButton:
                text: 'Btn5'
            ActionButton:
                text: 'Btn6'
            ActionButton:
                text: 'Btn7'