本文介紹了在 kivy (python) 中更新小部件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
誰能向我解釋一下您如何在 kivy 中更新小部件?我這里有一個代碼示例:
Can anyone explain to me how you update widgets in kivy? I have a code sample here:
class Game(Widget):
def __init__(self, **kwargs):
super(Game, self).__init__(**kwargs)
with self.canvas:
Color(*sky_color)
Rectangle(pos=(0, 0), size=self.size)
with self.canvas:
Color(*grass_color)
Rectangle(pos=(0,0), size=(800,75))
with self.canvas:
Label(text='Funky Chicken', font_size='50sp', pos=(360, 400))
with self.canvas:
Button(text='Play', font_size='20')
class FunkyChickenApp(App):
def build(self):
return Game(size=Window.size)
if __name__ == "__main__":
FunkyChickenApp().run()
這應(yīng)該是一個游戲菜單,所以當(dāng)你按下一些按鈕時,一些標(biāo)簽和東西必須改變.
This is supposed to be a game menu so some labels and stuff have to change when you press some buttons.
編輯*我的意思是如何使用 Kivy 時鐘
Edit* What i mean is how do I use Kivy clock
推薦答案
你需要給按鈕綁定動作(文檔有幾個例子https://kivy.org/docs/api-kivy.uix.button.html).
You need to bind actions to the buttons (the documentation has a few examples https://kivy.org/docs/api-kivy.uix.button.html).
即
button = Button(text='Play', font_size='20')
button.bind(on_press = do_something_you_want)
這篇關(guān)于在 kivy (python) 中更新小部件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!