我在 kivy 手风琴中加载了图像,当我按下鼠标按钮时,我想打印出图像下方的 x 和 y 坐标。我这辈子都想不出来。每次我添加任何东西时,它似乎都会关闭整个程序。我知道我拥有的小部件将打印到控制台,但我想将它打印到屏幕上。
这是我正在使用的代码:
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.uix.image import Image
from kivy.app import App
from kivy.uix.widget import Widget
class MouseWidget(Widget):
def on_touch_down(self, touch):
print(touch)
class MyApp(App):
def build(self):
root = Accordion(orientation='horizontal')
item= AccordionItem(title='Picture1')
src = "picture1.png"
image = Image(source=src,pos=(200, 100))
# add image to AccordionItem
item.add_widget(image)
root.add_widget(item)
item= AccordionItem(title='Picture2')
src = "picture2.png"
image = Image(source=src,pos=(200, 100))
# add image to AccordionItem
item.add_widget(image)
root.add_widget(item)
return root
if __name__ == '__main__':
MyApp().run()