问题描述
我对使用 kivy 库很陌生.
i'm pretty new at using kivy library.
我有一个 app.py 文件和一个 app.kv 文件,我的问题是我无法在按下按钮时调用函数.
I have an app.py file and an app.kv file , my problem is that I can't call a function on button press.
app.py:
app.kv:
推荐答案
Mode:.kv
很简单,say_hello
属于 Launch
类,所以要在 .kv
文件中使用它,你必须编写 <代码>root.say_hello.请注意,say_hello
是您要执行的函数,因此您不必忘记 ()
---> root.say_hello().
Mode:.kv
It's very simple, say_hello
belongs to the Launch
class so in order to use it in your .kv
file you have to write root.say_hello
. Note that say_hello
is a function that you want to execute so you don't have to forget the ()
---> root.say_hello()
.
另外,如果 say_hello
在 App
类中,您应该使用 App.say_hello()
因为它属于应用程序.(注意:即使你的 App 类是 class MyFantasicApp(App):
它总是 App.say_hello()
或 app.say_hello()
我不记得了,抱歉).
Also, if say_hello
were in App
class you should use App.say_hello()
because it belongs to the app. (Note: even if your App class were class MyFantasicApp(App):
it would always be App.say_hello()
or app.say_hello()
I don't remember, sorry).
模式:.py
你可以绑定
函数.
为什么要使用 bind
?对不起,不知道.但是您在 kivy 指南中使用了它.
Why use bind
? Sorry, no idea. But you it's used in the kivy guide.
这篇关于Python Kivy:如何在按钮单击时调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!