I am making a tkinter program where I want one button (button1) always on the screen. Every time that button is clicked I want a new button (button2) to form in a different area of the screen, each time the first button (button1) is clicked a new button (button2) should appear 30 pixels below the previous one. To do this I am using a counter. Where I am having an issue is when any one of the new buttons (button2) are clicked, I want the counter to reset. In other words, now when button1 is clicked, button2 should appear in the original spot again because the counter is 0 again. For some reason though my counter is never reseting and the new buttons (button2) just keep appearing lower than the last even after one of them is clicked. Please help thank you!
My code looks something like this:
My code looks something like this:
from tkinter import * window = Tk() counter = 0 def resetCounter(counter): counter = 0 def button1Clicked(): global counter button2 = Button(window, text="click me when ready", command(resetCounter(counter))) button2.place(x=50, y=(100 + (counter*30)) counter += 1 button1 = Button(window, text="click me" command(button1Clicked)) button1.place(x=0, y=0) window.mainloop()