如何使用kivy放大图像

2024-06-02 07:55:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图允许缩放,但我的大部分代码都在kivy中,而不是在.py文档中。我想让用户放大图像

BoxLayout:

    orientation: "vertical"
    Image:
        source: r"Dekalbprotocols (1)-026.jpg"
        allow_stretch: False
        keep_ratio: True
        size_hint: 1, 1

BoxLayout:

        orientation: "vertical"
        PageLayout:
            border: "100dp"
            Image:
                source: r"Dekalbprotocols (1)-019.jpg"
                allow_stretch: False
                keep_ratio: True

                size_hint: 1, 1

            Image:
                source: r"Dekalbprotocols (1)-020.jpg"
                allow_stretch: False
                keep_ratio: True

                size_hint: 1, 1
            Image:
                source: r"Dekalbprotocols (1)-021.jpg"
                allow_stretch: False
                keep_ratio: True

                size_hint: 1, 1

Tags: imagefalsetruesourcesizejpgallowkeep
1条回答
网友
1楼 · 发布于 2024-06-02 07:55:29

您可以像下面这样使用Scatter小部件

from kivy.app import App
from kivy.uix.image import AsyncImage
from kivy.uix.scatter import Scatter


class ZoomApp(App):
    def build(self):
        scatter = Scatter(do_translation=False,do_rotation=False)
        image = AsyncImage(source='https://images.unsplash.com/photo-1630629701731-56481a2dd34a?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1502&q=80')
        scatter.add_widget(image)
        return scatter


ZoomApp().run()



如果要使用鼠标进行缩放,需要右键单击图像的任意位置,然后左键单击进行缩放

相关问题 更多 >