我在我的 Kivy APP 中添加了一个文本输入窗口,我正在尝试用该窗口做两件事。默认情况下,文本输入窗口会突出显示双击的单词。我想将该词存储到一个变量中,但不知道如何将它从输入窗口传递给一个变量。其次,我试图从操作系统剪切并粘贴到 Kivy 中,但无法弄清楚。任何帮助将非常感激。这是我到目前为止的代码。感谢 Inclement 帮助我走到了这一步。
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: 'Test'
''')
class MouseWidget(BoxLayout):
image = ObjectProperty()
label = ObjectProperty()
source = StringProperty()
def on_touch_down(self, touch):
if self.image.collide_point(*touch.pos):
trigger = 0
if touch.x >= 133 and touch.x <= 646 and touch.y >= 162 and touch.y <=675:
self.label.text = str(touch.pos)
def on_touch_up(self, touch):
self.label.text = 'This is a test'
class TESTApp(App):
def build(self):
root = Accordion(orientation='horizontal')
item= AccordionItem(title='Test')
src = "image.png"
image = MouseWidget(source=src, size_hint = (1.0, 1.0))
textinput = TextInput(text='Hello world', size_hint = (0.5, 1.0))
textinput.bind(text2 = on_double_tap())
# add image to AccordionItem
item.add_widget(image)
item.add_widget(textinput)
root.add_widget(item)
return root
if __name__ == '__main__':
TESTApp().run()