How to make a button flashing?
Peter Otten
__peter__ at web.de
Wed Jun 13 07:21:31 EDT 2018
huey.y.jiang at gmail.com wrote:
> Hi All,
>
> I forgot the syntax of making a button flash, and failed to find an
> example in the web. I use Tkinter, to create a button. Then made it
> packed, and showed up. Now I am trying to make button b flashing, to make
> it get better noticed. I checked the docs, and found a method flash() is
> available, then I tried:
>
> b.flash()
>
> there was no error message popped out, but there was nothing happened
> also. I wonder who can give me this help? Thanks!
>
> Huey
Quoting http://tcl.tk/man/tcl8.6/TkCmd/button.htm#M16
"""
pathName flash
Flash the button. This is accomplished by redisplaying the button
several times, alternating between the configured activebackground and
background colors. At the end of the flash the button is left in the same
normal/active state as when the command was invoked. This command is ignored
if the button's state is disabled.
"""
So to see something you have to ensure that the two background colors
actually differ. Complete example:
import tkinter as tk
root = tk.Tk()
button = tk.Button(root, text="Hello")
button.pack()
button["activebackground"] = "red"
button["background"] = "silver"
root.after(1000, button.flash)
root.mainloop()
More information about the Python-list
mailing list