数字时钟显示-需要多线程吗? [英] Digital clock display - multithreading required?

查看:222
本文介绍了数字时钟显示-需要多线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

我有以下Tkinter窗口:

I have the following Tkinter window:

在右侧的空白处:

我希望能够不断更新时间,就像在数字时钟上一样.

I want to be able to continuously update the time, like on a digital clock.

我将使用以下时间:

time.strftime('%H:%<:%S')

我认为这涉及多线程.但是请告诉我是否还有其他方法可以做到这一点.

I think this involves MultiThreading. But please tell me if there is some other way to do this.

两个白色区域是用户的输入区域.

The two white areas are input areas for the user.

请注意,将在这些字段中输入文本.我不希望这受到影响.

Please note that the text will be entered in these fields. I don't want that to be affected.

我认为,该功能将使时间每秒钟更改一次,它将在与包含文本框的线程不同的线程上运行.

What I think is that the function that will make the time to change after each second, will run on a different thread than the one that includes the text boxes.

时间值将在标签中:

a = Label(root,text=time.strftime('%H:%M:%S'))

a.grid(row=3,column=1)

给我该功能以及多线程代码.

Please give me the code for this function and also for the multithreading.

帮助我解决此问题.

推荐答案

您不需要多线程.

...
a = Label(root, text=time.strftime('%H:%M:%S'))
def update_time():
    a['text'] = time.strftime('%H:%M:%S')
    root.after(1000, update_time)
root.after(1000, update_time)
a.grid(row=3, column=1)
...

这篇关于数字时钟显示-需要多线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆