本文介紹了加載表單后如何運行函數(shù) Kivy的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在 python 中有一個 kivy 程序,它有一個文本框和幾個按鈕.我已經(jīng)用 kivy 語言編寫了 ui,我需要運行一個更新文本框并等待用戶按下按鈕的函數(shù).當(dāng)所有小部件都已加載時,是否有我可以使用的 on_load 屬性或某種東西來運行此功能..kv 文件:
I have a kivy program in python which has a textbox and a few buttons. I have written the ui in kivy language and I need to run a function which updates the text box and waits for the user to press a button. Is there an on_load property I can use or some sort of thing to run this function when all the widgets have been loaded. The .kv file:
<MainGui>:
id: layout1
orientation: 'horizontal'
#I would like for some sort of event like below to run my function:
on_load: root.myfunction()
推薦答案
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
class DemoApp(App):
def build(self):
self.layout = layout = BoxLayout()
layout.label = Label(text="INITIAL TEXT")
layout.add_widget(layout.label)
return(self.layout)
def on_start(self, **kwargs):
self.layout.label.text = "APP LOADED"
DemoApp().run()
這篇關(guān)于加載表單后如何運行函數(shù) Kivy的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!