【发布时间】:2019-07-21 01:31:25
【问题描述】:
我想从 main 类访问一个 id 到 fahim2_pop 类。想要访问从文本输入(在主类中)到当有人按下搜索按钮时将出现的弹出小部件的单词。当有人搜索“hello”并按下搜索按钮时,弹出小部件将出现,并且在该弹出小部件中,标签的文本将与 textinput 中的“hello”相同。但标签和 id 仍然属于不同的类别。怎么办?
python 代码
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.properties import *
class fahim2_pop(Popup):
pass
class main(BoxLayout):
def word(self):
pop=fahim2_pop()
pop.open()
class go(BoxLayout):
def main(self):
self.clear_widgets()
self.add_widget(main())
class CallApp(App):
def build(self):
return go()
CallApp().run()
kv码
Builder.load_string('''
<main>:
BoxLayout:
orientation:"vertical"
TextInput:
id:word
Button:
text:"search"
on_press:root.word()
<go>:
Button:
text:"go"
on_press:root.go()
<fahim2_pop>:
id:pop
title:"result"
BoxLayout:
Label:
text:app.root.ids.word.text
''')
我知道 app.root.ids.word.text 如果该 id 保留在我的应用程序的根目录中。但这里是应用程序的根。如何从 fahim2_pop 类中的 main 类访问 id?
【问题讨论】: