I have a while loop that I want to run while the Tkinter window is open but the Tkinter window doesn't even open when the while loop is running.
This is a problem since my while loop is an infinite loop.
I basically want to create a programme that provides the users with new choices after a previous choice is selected by updating the buttons through a while loop, but whenever I use a while loop Tkinter doesn't open the window until I end the loop.
root = Tk()
i=0
while i==0:
def choice1():
list1[a1].implement()
list1.remove(list1[a1])
def choice2():
list2[a2].implement()
list2.remove(list2[a2])
button1 = tk.Button(root, text=list1.headline, command=choice1)
button2 = tk.Button(root, text=list2.headline, command =choice2)
root.mainloop()
Also, an error shows up because tkinter keeps executing this loop until there are no items in list1 or list2 left.
What I want to know is if there is a way to run Tkinter window while the while loop is going on
(a1 and a2 are randomly generated numbers.)

mainloop()from running. See @Bryan Oakley's answer to Tkinter — executing functions over time. Also note that your infinitewhileloop is doing nothing by defining the two functions over-and-over — they are never called in the loop.root.mainloop()in thewhileloop.mainloop()is the main reason for the window to be displayed continuously. When thewhile loopis running themainloop()does not get executed until thewhile loopends because the code including themainloop()waits till its turn to be executed. As the code on the top gets executed first.root.mainloop()in thewhileloop will prevent it from iterating because the former function won't return until the application window is closed — so it won't fix anything.