我需要一种方法,一个有一个按钮的类(转到高级选项),在发布弹出窗口打开(有自己的类)里面有texet输入和一个按钮,无论用户输入我需要的是什么单击(写入按钮)将其发送回第一个类(将打印texet输入值)
*********** python文件***********
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
class btn_(BoxLayout):
pass
class Var():
def PP_(self):
xx = self.textinput1.text
print (xx)
class Editor(App):
zozo = Var()
def build(self):
return btn_()
if __name__ == '__main__':
Editor().run()
**** KV文件*********
#:import Factory kivy.factory.Factory
<btn_>:
Button:
text: "Open PopUp"
on_release: Factory.Popup().open()
<Popup>:
textinput1: textinput1
BoxLayout:
TextInput:
id: textinput1
hint_text: "Write something"
Button:
text: "Write"
on_release: app.zozo.PP_()
答案 0 :(得分:0)
将TextInput.text
从kv文件中的类规则<Popup>:
传递到Python代码中的类Var()
的解决方案如下:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class btn_(BoxLayout):
pass
class Var():
def PP_(self, txt):
print(txt)
class Editor(App):
zozo = Var()
def build(self):
return btn_()
if __name__ == '__main__':
Editor().run()
#:import Factory kivy.factory.Factory
<btn_>:
Button:
text: "Open PopUp"
on_release: Factory.Popup().open()
<Popup>:
BoxLayout:
TextInput:
id: textinput1
hint_text: "Write something"
Button:
text: "Write"
on_release: app.zozo.PP_(textinput1.text)