【问题标题】:How do I positon inputed image file in kivymd如何在 kivymd 中定位输入图像文件
【发布时间】:2021-10-23 10:46:16
【问题描述】:

我制作了一个接受图像文件输入的简单应用程序,但是无论输入图像,它都会水平显示,而不是原始的垂直位置(我的意思是当输入图像时,它不是正常的,而是方向变化,希望你能理解。)

请问我该如何解决这个问题,所以输入图像的方向将与原始方向相同。非常感谢您的帮助。

这是我的代码:

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.core.window import Window
from plyer import filechooser

Window.size = (300, 530)

KV = """
MDBoxLayout:
    orientation: 'vertical'

    MDToolbar:
        id: progress_toolbar
        title: 'Progress'

    ScrollView:
        MDGridLayout:
            cols: 2
            adaptive_height: True
            spacing: (10, 15)
            padding: [25, 25]

            MDLabel:
                halign: 'center'
                text: 'Before'

            MDLabel:
                halign: 'center'
                text: 'Now'

            MDCard:
                ripple_behavior: True
                orientation: 'vertical'
                size_hint_y: None
                size: 120, 220
                elevation: 15
                radius: 8
                MDIconButton:
                    icon: "camera-outline"
                    user_font_size: "24sp"
                    pos_hint: {"center_x": .5, "center_y": .5}
                    on_release: app.file_chooser1()
                Image:
                    id: img1
                    allow_stretch: True
                    keep_ratio: False
                    # size_hint_y: .5

            MDCard:
                ripple_behavior: True
                orientation: 'vertical'
                size_hint_y: None
                size: 120, 220
                elevation: 15
                radius: 8
                MDIconButton:
                    icon: "camera-outline"
                    user_font_size: "24sp"
                    pos_hint: {"center_x": .5, "center_y": .5}
                    on_release: app.file_chooser2()
                Image:
                    id: img2
                    allow_stretch: True
                    keep_ratio: False
                    # size_hint_y: .5


            MDTextField:
                hint_text: 'Date'
                width: 100

            MDTextField:
                hint_text: 'Date'
                width: 100

"""


class Example(MDApp):

    def build(self):
        return Builder.load_string(KV)

    def file_chooser1(self):
        filechooser.open_file(on_selection=self.selected1)

    def file_chooser2(self):
        filechooser.open_file(on_selection=self.selected2)

    def selected1(self, selection1):
        self.root.ids.img1.source = selection1[0]

    def selected2(self, selection2):
        self.root.ids.img2.source = selection2[0]


Example().run()

非常感谢您的努力。

【问题讨论】:

    标签: python-3.x kivy kivy-language kivymd


    【解决方案1】:

    我认为你应该改变这个:

    来自

    MDCard:
        orientation: 'vertical'
    

    MDCard:
        orientation: 'horizontal'
    

    请分享屏幕截图以获得更多帮助

    【讨论】:

      猜你喜欢
      • 2021-12-09
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2023-03-12
      • 2021-08-24
      相关资源
      最近更新 更多