-2

I have this code python, while running the code does not show any error but when Please click on the button does not show the result

from tkinter import *

root = Tk()

def cal():
    l=[15,7,9,11]
    s=0
    for i in range(0,len(l)):
        s=s+l[i]
return s

b = Button(root, text="ok", command=cal())
b.pack()

label = Label(root, text=cal())
label.pack()

root.mainloop()
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
Kumar Pyth
  • 11
  • 1

1 Answers1

0

You need to store a reference to the function command=cal instead of storing the function's return value command=cal().

Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67