是否可以使用python中的屏幕对象来引用屏幕管理器? 基本上我想从python中更改屏幕。
在kivy中很简单:
app.root.current='ScreenName'
我不想在这里创建一个新的屏幕管理器对象。
我这样做是因为在kivy语言中我使用此代码:
on_release: root.select_experiment();app.root.current= 'StartExperiment'
root.select_experiment()
调用pop。我希望只有在弹出窗口被取消后才能转换到StartExperiment屏幕。从kivy开始,它发生在之前。
编辑:
Traceback (most recent call last):
File "C:\Users\sony\Desktop\test\main.py", line 171, in <module>
AppBaseClass().run()
File "C:\Anaconda\lib\site-packages\kivy\app.py", line 824, in run
runTouchApp()
File "C:\Anaconda\lib\site-packages\kivy\base.py", line 487, in runTouchApp
EventLoop.window.mainloop()
File "C:\Anaconda\lib\site-packages\kivy\core\window\window_sdl2.py", line 525, in mainloop
self._mainloop()
File "C:\Anaconda\lib\site-packages\kivy\core\window\window_sdl2.py", line 290, in _mainloop
EventLoop.idle()
File "C:\Anaconda\lib\site-packages\kivy\base.py", line 330, in idle
self.dispatch_input()
File "C:\Anaconda\lib\site-packages\kivy\base.py", line 315, in dispatch_input
post_dispatch_input(*pop(0))
File "C:\Anaconda\lib\site-packages\kivy\base.py", line 281, in post_dispatch_input
wid.dispatch('on_touch_up', me)
File "kivy\_event.pyx", line 699, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:7011)
File "C:\Anaconda\lib\site-packages\kivy\uix\behaviors.py", line 163, in on_touch_up
self.dispatch('on_release')
File "kivy\_event.pyx", line 695, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:6970)
File "kivy\_event.pyx", line 1168, in kivy._event.EventObservers.dispatch (kivy\_event.c:12154)
File "kivy\_event.pyx", line 1092, in kivy._event.EventObservers._dispatch (kivy\_event.c:11729)
File "C:\Users\sony\Desktop\test\main.py", line 84, in file_button_clicked
self.parent.ids.MyScreenManager.current = 'StartExperiment'
File "kivy\properties.pyx", line 720, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:10911)
AttributeError: 'super' object has no attribute '__getattr__'
答案 0 :(得分:1)
我认为最简单的方法是给屏幕管理员一个用kivy语言编写的ID,然后从Python中引用该ID。
ScreenManager:
id: MyScreenManager
self.parent.current = 'Target_Screen'