I want to creates buttons in a while loop, but when the app starts running, my program stops. It might be a beginner problem, but I cannot figure it out.
My code looks like this:
import tkinter as tk
app = tk.Tk()
app.geometry("600x300")
app.title("Test App")
con = tk.Frame(app)
ran = False
clicked = False
def setClicked():
globals()['clicked'] = True
while True:
if ran != True:
btn = tk.Button(con, text="Clickmepls", command=lambda: setClicked())
btn.pack(side=tk.TOP)
app.update()
con.pack()
ran = True
print("Lemme run")
else:
if clicked == True:
ran = False
clicked = False
print("You ran")
else:
app.update()
app.mainloop()
I tried putting pack and mainloop outside the while loop, which results in the program not starting. I tried adding update and update_idletasks but it didn't work.
clickedin the first place?