0

Sorry if this is a weirdly written question, i'm not usually one to ask them. I was working on a project to pass time while I am out of college and I thought it would be fun to put together a basic role-playing game. I decided to work on the battle system before I made anything for the over-world. Until yesterday I had no problems getting tkinter to run correctly and then, when I reorganised the code that I had written, my buttons started firing their commands when I declared them and stopped doing so when they are clicked. I went online looking for answers to my problem. When none of them worked, I threw together a basic version of the system I am using and I came here.

try:
    from tkinter import *
except:
    from Tkinter import *

master = Tk()

def callback():
    print("click!")

Button_Fight = Button(master, text="  Fight  ", command=callback(), height=4, width=24, font='Arial', state = DISABLED)

Button_Run = Button(master, text="   Run   ", command=callback(), height=4, width=24, font='Arial', state = DISABLED)



Button_Fight["state"] = NORMAL
Button_Fight.grid(column=1, row=1)

Button_Run["state"] = NORMAL
Button_Run.grid(column=2, row=2)

master.mainloop()

Any help at all would be very much appreciated.

Henry Yik
  • 22,275
  • 4
  • 18
  • 40

1 Answers1

0

I think your issue is that when you call a function in a tkinter object you don't put the parentheses. so for example replace this line of code:

command=callback(),

with this line:

command=callback,

This will make it so it calls the function when clicked rather than when you run the program.

Jonah.Checketts
  • 54
  • 2
  • 10