I'm using tkinter library for the GUI. Basically I'm creating 4 buttons using a for loop, each having a random number as their text. Now I got stuck when trying to implement a method which allows the button text to appear as a number and then change to nothing in a second or so (After this is done the next button would do the same process). So the method would allow each button to flash it's number and moves on to the next (Until all the buttons flashed their numbers for one time).
This is the code which I got so far
from tkinter import *
from tkinter.messagebox import showinfo
from random import randint
def set_colors(a):
if a == 0:
return "red"
elif a == 1:
return "green"
elif a == 2:
return "blue"
elif a == 3:
return "yellow"
def set_random():
random_int = 0
random_int = randint(0, 100)
return random_int
LARGE_FONT = ("Verdana",20)
color = 0
root = Tk()
frame = Frame(root)
root.title("Test")
root.geometry("200x200")
root.resizable(0, 0)
Grid.rowconfigure(root, 0, weight=1)
Grid.columnconfigure(root, 0, weight=1)
frame.grid(row=0, column=0, sticky=N + S + E + W)
grid = Frame(frame)
grid.grid(sticky=N + S + E + W, column=0, row=7, columnspan=2)
Grid.rowconfigure(frame, 7, weight=1)
Grid.columnconfigure(frame, 0, weight=1)
for x in range(2):
for y in range(2):
rand_no = set_random()
btn = rand_no
btn = Button(frame, text=btn, bg=set_colors(color) , font=LARGE_FONT)
btn.grid(column=x, row=y, sticky=N + S + E + W)
color += 1
for x in range(2):
Grid.columnconfigure(frame, x, weight=1)
for y in range(2):
Grid.rowconfigure(frame, y, weight=1)
root.mainloop()
A picture of the output.So far I figured that I need to import the time library and use the sleep() method to get the delay needed. But I still need to:
Allow the panel to load with the buttons (Without any numbers) Then the buttons start to flash the number one after each other until all buttons flashed the number for one time.
Memory is everything !