0
我試圖用Settings
屏幕創建應用程序(在ScreenManager
中)。如何將Settings
放入Screen
,以便我可以將Screen
放入ScreenManager
,因此當Screen
導航到Settings
實例時,它會被隱藏起來,並且會被導航離開它嗎?將Kivy的設置用作屏幕
我試圖用Settings
屏幕創建應用程序(在ScreenManager
中)。如何將Settings
放入Screen
,以便我可以將Screen
放入ScreenManager
,因此當Screen
導航到Settings
實例時,它會被隱藏起來,並且會被導航離開它嗎?將Kivy的設置用作屏幕
以下是關於如何使用2個屏幕的screenmanager的基本示例。
from kivy.app import App
from kivy.uix.screenmanager import Screen,ScreenManager
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
class ScreenOne(Screen):
def __init__(self,**kwargs):
super(ScreenOne,self).__init__(**kwargs)
self.box = BoxLayout(orientation='vertical')
self.label1 = Label(text="One label on screen 1")
self.label2 = Label(text="Another label label")
self.button = Button(text="Go to screen 2")
self.button.bind(on_press=self.change_screen)
self.box.add_widget(self.label1)
self.box.add_widget(self.label2)
self.box.add_widget(self.button)
self.add_widget(self.box)
def change_screen(self,*args):
self.manager.current = 'screen2'
class ScreenTwo(Screen):
def __init__(self,**kwargs):
super (ScreenTwo,self).__init__(**kwargs)
self.box = BoxLayout(orientation='vertical')
self.label1 = Label(text="One label on screen 2")
self.label2 = Label(text="Another label label")
self.button = Button(text="Go to screen 1")
self.button.bind(on_press=self.change_screen)
self.box.add_widget(self.label1)
self.box.add_widget(self.label2)
self.box.add_widget(self.button)
self.add_widget(self.box)
def change_screen(self,*args):
self.manager.current = 'screen1'
class MyApp(App):
def __init__(self,**kwargs):
super(MyApp,self).__init__(**kwargs)
self.sm = ScreenManager()
self.sm.add_widget(ScreenOne(name = "screen1"))
self.sm.add_widget(ScreenTwo(name = "screen2"))
def build(self):
return self.sm
if __name__ == "__main__":
MyApp().run()
你有什麼嘗試嗎?你的代碼現在如何? – EL3PHANTEN
顯示設置的標準方法似乎是'open_settings()',但在檢查返回值(布爾值)後,我不知道如何檢索窗口小部件以使屏幕實例存儲(並顯示)。 總之,我沒有明確地試圖將它附加到'Screen'上,因爲我看不到如何去做(即使文檔指出它可以添加到ScreenManager中)。 – FluxIX
所以你想要一個關於如何使用屏幕的例子? – EL3PHANTEN