kivy multiscreen找不到id

2024-06-01 08:26:46 发布

您现在位置:Python中文网/ 问答频道 /正文

总之,我不能将goi传递到kivy代码中VQCIA类中的submit\u goi函数中。如果有人能修改代码我会很感激的。print self.goi.text()语句报告了一个问题,它说AttributeError:'NoneType'对象没有属性'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()

我想做一个多屏幕应用程序,第一页是欢迎页面。第二个页面是用户可以提交表单的主页面。谢谢你


Tags: thetotextfromimportselfsizemanager