I am trying to display a random phrase from a dictionary every few seconds in a tkinter window.
I can get the phrase to display by just running a variable into a text box in tkinter, but I can't seem to get that phrase to change in the desired intervals.
So far this is the code that I have.
import time
import sys
import random
import tkinter as tk
from tkinter import *
""" DICTIONARY PHRASES """
phrases = ["Phrase1", "Phrase2", "Phrase3"]
def phraserefresh():
while True:
phrase_print = random.choice(phrases)
time.sleep(1)
return phrase_print
phrase = phraserefresh()
# Root is the name of the Tkinter Window. This is important to remember.
root=tk.Tk()
# Sets background color to black
root.configure(bg="black")
# Removes the window bar at the top creating a truely fullscreen
root.wm_attributes('-fullscreen','true')
tk.Button(root, text="Quit", bg="black", fg="black", command=lambda root=root:quit(root)).pack()
e = Label(root, text=phrase, fg="white", bg="black", font=("helvetica", 28))
e.pack()
root.mainloop()
The result of running this code is that the tkinter window never opens, as opposed to changing the displayed text. I know I must be over looking something simple but I can't seem to figure out what. Thanks for you help in advance!