当我在另一个小部件中单击鼠标时,我试图用新文本重置文本输入框,但我不太确定如何做到这一点。我尝试过以多种方式更改代码,但显然不是我在做什么。这是我正在使用的代码:感谢 inclement 和 qua-non 让我走到这一步
Builder.load_string('''
<MouseWidget>:
image: image
label: label
orientation: 'vertical'
Image:
id: image
source: root.source
Label:
id: label
size_hint_y: None
height: 50
text: 'Hello World'
''')
class Test(TextInput):
def on_double_tap(self):
# make sure it performs it's original function
super(Test, self).on_double_tap()
def on_word_selection(*l):
selected_word = self.selection_text
print selected_word
# let the word be selected wait for
# next frame and get the selected word
Clock.schedule_once(on_word_selection)
class MouseWidget(BoxLayout):
image = ObjectProperty()
label = ObjectProperty()
source = StringProperty()
正是在这个定义中,我想更新在 AccordianAPP 中创建并通过 TEST 发送的文本输入框,每次鼠标单击图像时都会使用新文本
def on_touch_down(self, touch):
if self.image.collide_point(*touch.pos):
self.label.text = str(touch.pos)
def on_touch_up(self, touch):
self.label.text = 'Hello World'
class AccordianApp(App):
def build(self):
root = Accordion(orientation='horizontal')
item= AccordionItem(title='Page One')
src = "image.png"
image = MouseWidget(source=src, size_hint = (1.0, 1.0))
这是我想在单击图像时将 text="" 重置为其他内容的文本输入
textinput = Test(text='Testing', size_hint = (0.5, 1.0))
# add image to AccordionItem
item.add_widget(image)
item.add_widget(textinput)
root.add_widget(item)
return root
if __name__ == '__main__':
AccordianApp().run()
谢谢您的帮助