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

查看:319
本文介绍了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.

后()运行 UPDATE_TIME 1秒后 UPDATE_TIME 使用后()来运行自己1秒后再次。这样 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天全站免登陆