如何通过引用其副标题来打印整段文本?

How to print a whole paragraph of text by referencing its subheading?

我正在制作一个简单的应用程序,当用户按下特定按钮时,它会为用户提供有关特定飞机的深入信息 caution/warning。我是新手,这可能是一个非常基本的问题,但我根本不知道该怎么做。

我不确定组织文本数据的最佳方式是将每个 caution/warning 放在单独的 .py 文件中其自己的字符串变量下,还是制作一个 class 每个 caution/warning 都有不同的模块,模块只是字符串信息。也许是字典?也许最好的方法是将其作为文本文件???

对于每个 caution/warning,将有大约 200 个单词描述与之相关的问题和解决方案。

我的意思的一个非常简短的例子是:如果有人按下“电池”警告,按钮会调用 main.py 中的 get_text 函数并将按钮的 [=17] 发送给它=]. get_text 使用发送给它的 id 然后从 AOM.py.txt 或其他任何地方提取文本。然后,该信息将显示在页面上,大约 200 字,说明电池的问题是什么以及如何解决。 (我故意忽略了在我的示例中更改屏幕的需要,因为我知道该怎么做)。我现在只是作为 print() 离开。

我这里有一个最小可重现的例子,如果有人可以帮助我吗?非常感谢。

main.py

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
import AOM

class CautionPanelScreen(Screen):
    pass
class TextScreen(Screen):
    pass

GUI = Builder.load_file("main.kv")
class MainApp(App):
    def build(self):
        return GUI

    def change_screen(self):
        # get the screen manager from the main.kv file
        screen_manager = self.root.ids['screen_manager']
        screen_manager.current = 'text_screen'

    def get_text(self, caution):
        print(AOM.caution)             # this is where i am stuck, I dont know how to ref the data...

MainApp().run()

main.kv

#:include caution_panel_screen.kv
#:include text_screen.kv
GridLayout:
    cols: 1
    FloatLayout:
        GridLayout:
            canvas:
                Color:
                    rgb: utils.get_color_from_hex("#EEEEEE")
                Rectangle:
                    size: self.size
                    pos: self.pos
        ScreenManager:
            id: screen_manager
            CautionPanelScreen:
                name: "caution_panel_screen"
                id: caution_panel_screen

caution_panel_screen.kv

#:import utils kivy.utils
<CautionPanelScreen>:
    FloatLayout:
        flt_data_recorder: flt_data_recorder.__self__
        canvas:
            Color:
                rgb: utils.get_color_from_hex("#000000")
            Rectangle:
                size: self.size
                pos: self.pos
        GridLayout:
            rows: 1
            id: row_1
            pos_hint: {"top": .9, "left": 1}
            size_hint: 1, .1
            spacing: 5, 5
            Button:
                pos_hint: {"top": 1, "left": 1}
                markup: True
                opacity: 1 if self.state == 'normal' else .5
                font_size: '12sp'
                id: pri_inv
                halign: 'center'
                text: "[color=#FFF300]PRI INV[/color]"
                on_release:
                    app.get_text(pri_inv)
            Button:
                pos_hint: {"top": 1, "left": 1}
                markup: True
                opacity: 1 if self.state == 'normal' else .5
                font_size: '12sp'
                id: l_ac_bus
                halign: 'center'
                text: "[color=#FFF300]L AC BUS[/color]"
                on_release:
                    app.get_text(l_ac_bus)
            Button:
                pos_hint: {"top": 1, "left": 1}
                markup: True
                opacity: 1 if self.state == 'normal' else .5
                font_size: '12sp'
                id: emer_lts_disarmed
                halign: 'center'
                text: "[color=#FFF300]EMER LTS\nDISARMED[/color]"
                on_release:
                    app.get_text(emer_lts_disarmed)

AOM.py

#THIS IS JUST THE DATA PAGE AND CAN BE LAID OUT IN ANY WAY, dictionary, variables, txt, module, functions...
pri_inv = "all the things assosicated with primary inverter"
left_ac_bus = "all the stuff needed for info on left ac buses"
emer_lts_disarmed = "evertyhing on emergency  lights"

编辑: 我必须将文本存储在 main.py 上吗?或者我可以把它分开,比如在 word 文档中吗?

我会保留它作为字典

AOM.py

data = {
    'pri_inv': "all the things assosicated with primary inverter",
    'left_ac_bus': "all the stuff needed for info on left ac buses",
    'emer_lts_disarmed': "evertyhing on emergency  lights",
}    

Button应该使用get_text()中的字符串on_release

     on_release:
         app.get_text("pri_inv")


     on_release:
         root.get_text("left_ac_bus")


     on_release:
         app.get_text("emer_lts_disarmed")

然后代码应使用此字符串从 AOM.data

获取文本
    def get_text(self, caution):
        print(AOM.data[caution])  

也许以后我会使用 AOM.data 生成 Button 所以我会在 AOM.data

中保留按钮的文本
data = {
    'pri_inv': ["PRI INV", "all the things assosicated with primary inverter"],
    'left_ac_bus': ["L AC BUS", "all the stuff needed for info on left ac buses"],
    'emer_lts_disarmed': ["EMER LTS\nDISARMED", "evertyhing on emergency  lights"],
}    

然后它需要使用索引[1]来获取文本

    def get_text(self, caution):
        print(AOM.data[caution][1])  

或者它可以保留在嵌套词典中

data = {
    'pri_inv': {
         "button_text": "PRI INV", 
         "text": "all the things assosicated with primary inverter",
    },
    'left_ac_bus': {
         "button_text": "L AC BUS", 
         "text": "all the stuff needed for info on left ac buses",
    },
    'emer_lts_disarmed': {
         "button_text": "EMER LTS\nDISARMED", 
         "text": "evertyhing on emergency  lights",
    },
}    

然后它需要使用["text"]来获取文本

    def get_text(self, caution):
        print(AOM.data[caution]["text"])  

如果按钮有其他唯一值,那么我也会保留它们 在字典里。