I'm relatively new to python, so please bear with me.
My question has two aspects:
-
First, I'm trying to make a GUI that randomly pops different sentences to the user, every time in a new frame.
-
Second, I want the user to be able to close the GUI without stopping the script, like if it was running in the background.
here is my code:
import Tkinter as tk
import random
number = random.randint(0,13)
sentence = {contains 13 sentences
}
window = tk.Tk()
window.output = tk.Label(text = sentence[number])
window.title("I Always See You")
window.geometry("300x150")
def next():
rand= random.randint(0, 13)
window2 = tk.Tk()
window2.output = tk.Label(text = sentence[rand])
window2.output.pack(side="top", fill="x", expand=True)
window2.title("I Always See You")
window2.geometry("300x150")
window.output.pack(side="top", fill="x", expand=True)
choice()
window.after(1000, next)
window.mainloop()
My problem: when my second frame pops, there isn't any text showing, and if it does have something popping, it appears in the first frame.
also, how can you insert a random float in .after() ?
Thank you so much for your help!
cheers
Aucun commentaire:
Enregistrer un commentaire