kivy multiscreen 找不到id
kivy multiscreen can not find the id
全部,我无法在我的 kivy 代码中将 goi 传递给 class VQCIA 中的函数 submit_goi。如果有人可以修复代码,我将不胜感激。 print self.goi.text() 语句报错,报AttributeError: 'NoneType' object has no attribute 'text'。这真的很奇怪。
# ---------- vqcia.py ----------
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
Builder.load_string("""
<HelloVQCIA>:
BoxLayout:
Button:
text: "Welcome to VQCIA"
on_press:
# You can define the duration of the change
# and the direction of the slide
root.manager.transition.direction = 'left'
root.manager.transition.duration = 1
root.manager.current = 'screen_two'
<VQCIA>:
BoxLayout:
orientation: "vertical"
goi: g_o_i
padding: 10
spacing: 10
size: 400, 200
pos: 200, 200
size_hint:None,None
BoxLayout:
Label:
text: "Enter gene of interest with TAIR ID:"
font_size: '25sp'
BoxLayout:
TextInput:
id: g_o_i
hint_text: 'AT3G20770'
multiline: False
font_size: '25sp'
BoxLayout:
Button:
text: "Submit"
size_hint_x: 15
on_press:
root.submit_goi()
""")
class HelloVQCIA(Screen):
pass
class VQCIA(Screen):
# Connects the value in the TextInput widget to these
# fields
goi = ObjectProperty()
def submit_goi(self):
print self.goi.text
# The ScreenManager controls moving between screens
screen_manager = ScreenManager()
# Add the screens to the manager and then supply a name
# that is used to switch screens
screen_manager.add_widget(HelloVQCIA(name="screen_one"))
screen_manager.add_widget(VQCIA(name="screen_two"))
class VQCIAApp(App):
def build(self):
return screen_manager
dbApp = VQCIAApp()
dbApp.run()
我想做一个多屏应用,首页是欢迎页面。第二页是用户可以提交表单的主页。谢谢。
在kv文件中,将goi: g_o_i
移动到class规则之后,<VQCIA>:
<VQCIA>:
goi: g_o_i
BoxLayout:
orientation: "vertical"
全部,我无法在我的 kivy 代码中将 goi 传递给 class VQCIA 中的函数 submit_goi。如果有人可以修复代码,我将不胜感激。 print self.goi.text() 语句报错,报AttributeError: 'NoneType' object has no attribute 'text'。这真的很奇怪。
# ---------- vqcia.py ----------
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
Builder.load_string("""
<HelloVQCIA>:
BoxLayout:
Button:
text: "Welcome to VQCIA"
on_press:
# You can define the duration of the change
# and the direction of the slide
root.manager.transition.direction = 'left'
root.manager.transition.duration = 1
root.manager.current = 'screen_two'
<VQCIA>:
BoxLayout:
orientation: "vertical"
goi: g_o_i
padding: 10
spacing: 10
size: 400, 200
pos: 200, 200
size_hint:None,None
BoxLayout:
Label:
text: "Enter gene of interest with TAIR ID:"
font_size: '25sp'
BoxLayout:
TextInput:
id: g_o_i
hint_text: 'AT3G20770'
multiline: False
font_size: '25sp'
BoxLayout:
Button:
text: "Submit"
size_hint_x: 15
on_press:
root.submit_goi()
""")
class HelloVQCIA(Screen):
pass
class VQCIA(Screen):
# Connects the value in the TextInput widget to these
# fields
goi = ObjectProperty()
def submit_goi(self):
print self.goi.text
# The ScreenManager controls moving between screens
screen_manager = ScreenManager()
# Add the screens to the manager and then supply a name
# that is used to switch screens
screen_manager.add_widget(HelloVQCIA(name="screen_one"))
screen_manager.add_widget(VQCIA(name="screen_two"))
class VQCIAApp(App):
def build(self):
return screen_manager
dbApp = VQCIAApp()
dbApp.run()
我想做一个多屏应用,首页是欢迎页面。第二页是用户可以提交表单的主页。谢谢。
在kv文件中,将goi: g_o_i
移动到class规则之后,<VQCIA>:
<VQCIA>:
goi: g_o_i
BoxLayout:
orientation: "vertical"