Найти - Пользователи
Полная версия: Как сделать анимацию текста через canvas в Python Tkinter?
Начало » Python для новичков » Как сделать анимацию текста через canvas в Python Tkinter?
1
Vilgelm
Мне нужно сделать анимацию теста 3… 2… 1… в Tkinter Python через canvas
Примерно вот такую:
Пример
DamMercul
 #coding=utf-8
from tkinter import *
import time
root = Tk()
root.title("Let's smile!")
countdown = 4
txt = "Smile at "
bg = Label(master=root, bg="black", fg="white", font="Arial 70", text=txt + str(countdown))
bg.pack()
def starting(ev):
    global txt, countdown
    if ev == "Enter":
        while countdown != 0:
            time.sleep(0.5)
            countdown -= 1
            bg["text"] = txt + str(countdown)
            bg.update()
            time.sleep(1)
        bg["text"] = "Done!"
root.bind("Space", starting(ev="Enter"))
root.mainloop()

В бинде для root я специально поставил функцию с вызовом, хотя для получения event'а надо без скобок. Я так сделал чтобы отчет начался сразу. Если надо, чтобы вместе с нажатием Enter начиналось, то:
 root.bind("Space", starting(ev="Enter"))
замени на:
 root.bind("<KeyPress>", starting)



This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB