如何在 Kivy/Python 的另一个屏幕中从一个屏幕引用 TextInput?

我正在尝试制作一个可以计算圆锥体体积的应用程序(到目前为止)。我有一个名为 ConeVolumeScreen 的屏幕,它有两个 TextInput 小部件。


<ConeVolumeScreen>:

    BoxLayout:

        orientation: ...

        padding: ...

        spacing: ...

        Label:

            text: 'Radius:'

        TextInput:

            id: cone_vol_radius

            multiline: False

            input_type: 'number'

        Label:

            text: 'Height:'

        TextInput:

            id: cone_vol_height

            multiline: False

            input_type: 'number'

        Button:

            text: 'Solve'

            on_release: app.root.changeScreen('solve cone volume')               

一个人应该在这两个小部件中输入圆锥的半径和高度。然后这个人可以点击一个按钮进入下一个名为 SolveConeVolumeScreen 的屏幕。在此屏幕中有一个标签,应打印该人指定的锥体体积。


<SolveConeVolumeScreen>:

    BoxLayout:

        orientation: ...

        padding: ...

        spacing: ...

        Label:

            text: app.getConeVolume(cone_vol_radius, cone_vol_height)

getConeVolume() 是这里的一个方法


class CalculatorRoot(BoxLayout):

    def __init__(self, **kwargs):

        super(CalculatorRoot, self).__init__(**kwargs)

        self.screen_list = []


    def changeScreen(self, next_screen):

        if self.ids.calc_screen_manager.current not in self.screen_list:

            self.screen_list.append(self.ids.calc_screen_manager.current)


        if next_screen == 'volume':

            self.ids.calc_screen_manager.current = 'volume_screen'

        elif next_screen == 'area_screen':

            self.ids.calc_screen_manager.current = 'area_screen'

        elif next_screen == 'surface area':

            self.ids.calc_screen_manager.current = 'surfarea_screen'


但是错误说没有定义cone_vol_radius。


 ...

 128:        spacing: min(root.width, root.height) * .02

 129:        Label:

130:文本:app.getConeVolume(cone_vol_radius,cone_vol_height)131:132:: ... BuilderException:解析器:文件“/Users/fayzulloh/Desktop/Calculator App/calculator.kv”,第130行:... 128:间距: min(root.width, root.height) * .02 129: 标签: 130: text: app.getConeVolume(cone_vol_radius, cone_vol_height) 131: 132:: ... NameError: name 'cone_vol_radius' 未定义


请帮忙。我真的很感激任何建议。


慕桂英4014372
浏览 165回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python