我引用的代码来自ikolim的答案:Why is my Kivy Actionbar gone?
这是我的python代码:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.core.window import Window
Window.clearcolor = (1,1,1,1)
Builder.load_file("designdawkalamomarunong.kv")
class Menu(BoxLayout):
manager = ObjectProperty(None)
class Add(Screen):
pass
class Help(Screen):
pass
class Credits(Screen):
pass
class Manager(ScreenManager):
addScreen = ObjectProperty(None)
helpScreen = ObjectProperty(None)
creditsScreen = ObjectProperty(None)
class AntsApp(App):
def build(self):
return Menu()
if __name__ == '__main__':
AntsApp().run()
这是猕猴桃代码:
<Menu>:
manager: screen_manager
orientation: "vertical"
ActionBar:
size_hint_y: 0.1
ActionView:
ActionPrevious:
ActionButton:
text: "Add"
on_release: app.root.current = "add"
ActionButton:
text:"Help"
on_release: app.root.current = "help"
ActionButton:
text: "Credits"
on_release: app.root.current = "credits"
Manager:
id: screen_manager
<Add>:
text: "hello boi"
<Help>:
text: "hello world"
<Credits>:
text: "goodbye world lol"
<Manager>:
id: screen_manager
addScreen: addScreen
helpScreen: helpScreen
creditsScreen: creditsScreen
Add:
id: addScreen
name: 'add'
manager: screen_manager
Help:
id: helpScreen
name: 'help'
manager: screen_manager
Credits:
id: creditsScreen
name: 'credits'
manager: screen_manager
当我单击操作栏上的按钮时,它不会返回任何内容。我还应该添加其他内容吗?预先谢谢你:)
编辑: 尝试这样做:
<Add>:
Button:
text: "hello boi"
它有效,但是当我尝试这样做时:
<Add>:
Label:
text: "hello boi"
它不起作用。我在这里想念什么?
答案 0 :(得分:1)
app.root.current
替换所有出现的root.manager.current
,因为root
是BoxLayout
小部件,而不是ScreenManager
小部件。Label
之前都缺少text
小部件。rgba=1, 1, 1, 1
),而BoxLayout的颜色也是白色。因此,您将无法看到文本。如果使用“标签”小部件,请添加color: (0, 0, 0, 1) # black color text
。#:kivy 1.11.0
<Menu>:
manager: screen_manager
orientation: "vertical"
ActionBar:
size_hint_y: 0.1
ActionView:
ActionPrevious:
ActionButton:
text: "Add"
on_release: root.manager.current = "add"
ActionButton:
text:"Help"
on_release: root.manager.current = "help"
ActionButton:
text: "Credits"
on_release: root.manager.current = "credits"
Manager:
id: screen_manager
<Add>:
Label:
text: "hello boi"
color: 0, 0, 0, 1 # black color text
<Help>:
Label:
text: "hello world"
color: 0, 0, 0, 1 # black color text
<Credits>:
Label:
text: "goodbye world lol"
color: 0, 0, 0, 1 # black color text
<Manager>:
addScreen: addScreen
helpScreen: helpScreen
creditsScreen: creditsScreen
Add:
id: addScreen
name: 'add'
Help:
id: helpScreen
name: 'help'
Credits:
id: creditsScreen
name: 'credits'