Skip to content Skip to sidebar Skip to footer

How To Make A Flashing Text Box In Tkinter?

So my computing class are making a xmas card in python, and for one of the bits there is going to be a text box with a message, but how do I make the background alternate from gree

Solution 1:

Create a change_color callback that alternates the text box's color, and uses after to call itself a second in the future.

Sample implementation:

from tkinter import *

def change_color():
    current_color = box.cget("background")
    next_color = "green" if current_color == "red" else "red"
    box.config(background=next_color)
    root.after(1000, change_color)

root = Tk()
box = Text(root, background="green")
box.pack()
change_color()
root.mainloop()

Post a Comment for "How To Make A Flashing Text Box In Tkinter?"