简体   繁体   English

Kivy用按钮python代码更改屏幕

[英]Kivy Changing screens with buttons python code

I keep getting this error 我不断收到这个错误

TypeError: __init__() takes 1 positional argument but 2 were given TypeError: __init__()接受1个位置参数,但给出了2个

I tried everything to make it work but it still seems not to work. 我尽了一切努力使其工作,但似乎仍然无法正常工作。 I'm trying to make an button where you click it if makes you go to a different screen but in python code. 我试图制作一个按钮,如果您使用python代码转到其他屏幕,则单击该按钮。

self.add_widget(ImageButton(source=('Image.png'), size=(200,200), size_hint=(0.2, 0.2), on_press=ScreenFive, pos_hint={"x":0.3, "top":0.7}))

Can you help me? 你能帮助我吗? Thanks! 谢谢!

You sent ScreenFive as callback for on_press . 您将ScreenFive发送为on_press的回调。 the callback is called with the button instance so your error raise. 使用按钮实例调用回调 ,因此会引发错误。

try this: 尝试这个:

def callback(instance):
    sm.current = "screen_five"

... ... on_press=callback

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

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