简体   繁体   English

如何在 kivy 或 kivymd 中正确使用 on_resize function

[英]how to properly use on_resize function in kivy or kivymd

In my app i need to call certain function in certain screen when it is resized, and it looks like this在我的应用程序中,当调整大小时,我需要在某些屏幕中调用某些 function,它看起来像这样

class MainApp(MDApp):
    def on_resize(self):
        if self.manager.get_screen() == "table_screen":   
            if self.width>self.height:
                self.manager.get_screen("table_screen").ids.table_image.source="table1.png"
                self.manager.get_screen("table_screen").ids.left_panel.opacity=0
                print("PAPAPAPPAAPPA")
            else:
                self.ids.left_panel.size_hint_x=.5
                self.ids.left_panel.opacity=1
                print("PAPAPAPPAAPPA")

    def build(self):
        Window.bind(size=self.on_resize)
        return Main()

but when i resize window in any screen, the image shatters and i get an error on_resize() takes 1 positional argument but 3 were given what is the origin of this error?但是当我在任何屏幕上调整 window 的大小时,图像会破碎并且我得到一个错误 on_resize() 需要 1 个位置参数,但是给出了 3 个这个错误的根源是什么? I dont see to give 3 argument anywhere我看不到在任何地方给出 3 个论点

The origin of the error is that when you bind a function to a property change, it receives three positional arguments.错误的根源是当您将 function 绑定到属性更改时,它会收到三个位置 arguments。 They are self , the instance of the class instance whose property is changing, and the new value of the property.它们是self ,其属性正在更改的 class 实例的实例,以及该属性的新值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM