导航抽屉没有显示在屏幕上

时间:2017-03-10 17:44:01

标签: python kivy

我不知道出了什么问题。没有错误,但导航抽屉没有显示

下面的

是python源:mainmenu.py

from kivy import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.garden.navigationdrawer import NavigationDrawer

class Drawer(NavigationDrawer):
    pass

class MainMenuApp(App):

    def show_drawer(self):
        d = Drawer()
        d.toggle_state()

    def build(self):
        return DrawerBox()

if __name__ == "__main__":
    MainMenuApp().run()
在kivy语言源下面:mainmenu.kv

<Drawer>:
    title: "Main Menu"
    BoxLayout:
        orientaion: "vertical"
        Button:
            text: "1"
        Button:
            text: "1"
        Button:
            text: "1"
        Button:
            text: "1"
        Button:
            text: "1"

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。我再次阅读文档。导航抽屉有两个面板侧面板和主面板 - 我只创建了侧面板。

在我的更正之下:

mainmenu.py

from kivy import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.garden.navigationdrawer import NavigationDrawer

class Drawer(NavigationDrawer):
    pass

class MainMenuApp(App):

    def show_drawer(self):
        d = Drawer()
        d.toggle_state()

    def build(self):
        return Drawer()

if __name__ == "__main__":
    MainMenuApp().run()

mainmenu.kv

<Drawer>:
title: "Main Menu"

# Side panel
BoxLayout:
    orientation: "vertical"
    Button:
        text: "Button 1"
    Button:
        text: "Button 2"
    Button:
        text: "Button 3"

# Main panel
BoxLayout:
    orientation: "vertical"
    Button:
        text: "Show Side Panel"
        on_press: root.toggle_state()