[英]Trying to change between screens when the ScreenManager is inside a BoxLayout of a Widget in Kivy
I have a problem, when pressing the button "Next screen", that's not working, and My First Windows is not changing to SecondWindow(Screen)..the app.root.current= 'second' is not working in in the kv.file.我有一个问题,当按下“下一个屏幕”按钮时,它不起作用,我的第一个 Windows 没有更改为 SecondWindow(Screen)..app.root.current='second' 在 kv 中不起作用。文件。 And I want to change just the part of the screens(WindowManager:FirstWindow, SecondWindow) and not all MyLayout.. The part of Mylayout have to stay there and just change the screens that those are below of this.而且我只想更改屏幕的一部分(WindowManager:FirstWindow,SecondWindow)而不是所有 MyLayout .. Mylayout 的部分必须留在那里并且只更改屏幕下方的屏幕。
py.file文件
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.core.spelling import Spelling
from kivy.uix.screenmanager import ScreenManager, Screen
kv= Builder.load_file('test2.kv')
class MyLayout(Widget):
def spinner_clicked(self,value):
self.ids.Label1.text= f'You selected: {value}'
#Definine our different screens
class FirstWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
class AwesomeApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
AwesomeApp().run()
kv.file kv文件
<MyLayout>
BoxLayout:
orientation:"vertical"
size: root.width, root.height
GridLayout:
cols:3
rows:3
Spinner:
id: spinner_id
text: "Menu"
values: ["Catalogue","Buy","Payment Methods", "Contact"]
on_text: root.spinner_clicked(spinner_id.text)
Label:
id: Label1
text: "My Panel"
Button:
text:"Buy"
#THESE SCREENS ARE NOT CHANGING
WindowManager:
FirstWindow:
SecondWindow:
<FirstWindow>:
name: "first"
BoxLayout:
orientation: "vertical"
size: root.width, root.height
Label:
text: "First Screen"
font_size: 32
Button:
text: "Next Screen"
font_size: 32
on_release:
app.root.current= "second"
root.manager.transition.direction= "left" #up
<SecondWindow>:
name: "second"
BoxLayout:
orientation: "vertical"
size: root.width, root.height
Label:
text: "Second Screen"
font_size: 32
Button:
text: "Go Back"
font_size: 32
on_release:
app.root.current= "first"
root.manager.transition.direction= "right"
Change your app.root.current
references in your kv
to root.manager.current
as I suggested in your previous question.按照我在上一个问题中的建议,将kv
中的app.root.current
引用更改为root.manager.current
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.