1

When I run the code "15" is immediately printed to console. How can I get it to print after I press the button?

from tkinter import *
def mult(n):
    print (n*3)

top = Tk()
B1 = Button(top, text = "Enter Number", command = mult(5))
B1.pack()
top.mainloop()
Daringa
  • 27
  • 7
  • 1
    Take a look at [Why is Button parameter “command” executed when declared?](http://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared). – galah92 Sep 07 '16 at 22:03

1 Answers1

1

Function arguments are fully evaluated before calling the function.

Make it into a callable:

from tkinter import *
def mult(n):
    print (n*3)

top = Tk()
B1 = Button(top, text = "Enter Number", command = lambda: mult(5))
B1.pack()
top.mainloop()
wim
  • 338,267
  • 99
  • 616
  • 750