Python Forum
tkinter button not accessing the command when clicked
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter button not accessing the command when clicked
#1
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:

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()
Reply


Messages In This Thread
tkinter button not accessing the command when clicked - by jhf2 - Nov-23-2019, 03:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 982 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 849 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,769 May-25-2023, 07:37 PM
Last Post: deanhystad
  tkinter.TclError: can't invoke "canvas" command cybertooth 8 5,976 Feb-23-2023, 06:58 PM
Last Post: deanhystad
  Can't get tkinter button to change color based on changes in data dford 4 3,419 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] Button 'command' Argument Confusion gw1500se 11 5,873 Nov-11-2021, 08:45 PM
Last Post: menator01
  [PyQt] Button clicked not working catlessness 10 8,227 Oct-21-2021, 12:36 PM
Last Post: catlessness
  Creating a function interrupt button tkinter AnotherSam 2 5,531 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,012 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  tkinter showing image in button rwahdan 3 5,626 Jun-16-2021, 06:08 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020