本文介紹了如何在 Kivy 中有更新時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在 kivy 中創建日歷應用程序,我想知道如何添加更新時鐘?我可以使用 datetime python 函數,但是當我在我的應用程序中加載它時,它會顯示一個沒有移動的凍結時間.有什么建議嗎?
I am creating a calendar app in kivy, and I was wondering how I would be able to add an updating clock? I can use the datetime python function, but when I load it in my app it shows a frozen time with no movement. Suggestions?
from datetime import datetime, date, time, timedelta
from kivy.app import App
from kivy.clock import Clock
(已解決)
推薦答案
這里有一個完整的例子來說明如何使用這個功能.您應該能夠從中工作并將其應用于您自己的代碼.如果您有任何具體問題,請在評論中告訴我,我很樂意回答:)
Here's a complete example of how to get this feature working. You should be able to work from this and apply it to your own code. If you have any specific questions, let me know in a comment and I'll be happy to answer :)
from kivy.app import App
from datetime import datetime
from datetime import timedelta
from kivy.clock import Clock
from kivy.uix.label import Label
class MyApp(App):
def build(self):
self.now = datetime.now()
# Schedule the self.update_clock function to be called once a second
Clock.schedule_interval(self.update_clock, 1)
self.my_label = Label(text= self.now.strftime('%H:%M:%S'))
return self.my_label # The label is the only widget in the interface
def update_clock(self, *args):
# Called once a second using the kivy.clock module
# Add one second to the current time and display it on the label
self.now = self.now + timedelta(seconds = 1)
self.my_label.text = self.now.strftime('%H:%M:%S')
MyApp().run()
這篇關于如何在 Kivy 中有更新時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!