Tkinter 文本动画? [英] Tkinter Text Animation?

查看:33
本文介绍了Tkinter 文本动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能以任何方式在 Tkinter 或 Python 中制作文本动画?(虽然程序是基于 Tkinter 的)

would it be possible in any way to do a text animation in Tkinter or Python in general? (Although the program is based in Tkinter)

例如,可能文本的字符一个接一个地出现,就像您打字非常快一样.有没有办法做到这一点?

For example, maybe the characters of the text appearing one after another kind of like you are typing it very fast. Is there any way to do this?

非常感谢.

推荐答案

示例 - 在标签上显示当前时间.

Example - display current time on label.

after() 在 1s 后运行 update_time 并且 update_time 使用 after() 在 1s 后再次运行自己.这样update_time被多次调用,它可以多次更改标签.

after() runs update_time after 1s and update_time uses after() to runs itself again after 1s. This way update_time is called many times and it can change label many times.

import tkinter as tk # Python 3.x
import time

# function which changes time on Label 
def update_time():
    # change text on Label
    lbl['text'] = time.strftime('Current time: %H:%M:%S')

    # run `update_time` again after 1000ms (1s)
    root.after(1000, update_time) # function name without ()


# create window
root = tk.Tk()

# create label for current time
lbl = tk.Label(root, text='Current time: 00:00:00')
lbl.pack()

# run `update_time` first time after 1000ms (1s)
root.after(1000, update_time) # function name without ()
#update_time() # or run first time immediately

# "start the engine"
root.mainloop()

这篇关于Tkinter 文本动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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