Home > OS >  Trying to create a red-translucent , flashing gui with tkinter
Trying to create a red-translucent , flashing gui with tkinter

Time:05-27

from tkinter import *

parent = Tk()
parent.geometry('500x500')
parent.title('Test in progress...')
parent.attributes('-alpha',0.5)
#parent.attributes('-fullscreen', True)
button1 = Button(parent, text = 'FOUND!',fg='red', command=parent.destroy)
button1.pack()
parent.mainloop()

I want this to flash translucent-red on fullscreen without effecting the user abilty to select things.

CodePudding user response:

Using some help from this answer I think I have something to help you. You need to have a function that will control the changes to color utilizing .after. It shifts from white transparent to red in a "flashing" like manner. I hope this is in the ballpark for what you want.

from tkinter import *


def change_color():
    current_color = parent.cget("bg")
    next_color = "white" if current_color == "red" else "red"
    parent.config(background=next_color)
    parent.after(1000, change_color)


parent = Tk()
parent.config(bg="red")
parent.attributes('-alpha', 0.5)
parent.geometry('500x500')
parent.title('Test in progress...')


button1 = Button(parent, text='FOUND!', fg='red', command=parent.destroy)
button1.pack()

change_color()
parent.mainloop()
  • Related