0

I had write a menu code in Tkinter which includes 2 mathematics programs.Each of these two programs run separately without any problems,but if you run this program it doesn't show anything in the result label.Please help me to solve this problem.

from tkinter import *
def case37():
    def cal37():
        number=int(e37.get())
        sumation=0
        for i in range(1,number+1):
            sumation+=1/(2**(i-1))
        result_var.set(sumation)
    
    window=Tk()

    Label(window,text='this is a series:').grid(row=0,column=0)
    Label(window,text='S=1,1/2,1/4,1/8,...').grid(row=0,column=1)
    Label(window,text='enter number of statement?').grid(row=1,column=0)
    label=Label(window,text='result:')
    label.grid(row=3,column=0)

    e37=Entry(window)
    e37.grid(row=1,column=1)

    Button(window,text='calculate',command=cal37,padx=10).grid(row=2,column=0,columnspan=2)

    result_var=StringVar()
    result=Label(window,textvariable=result_var)
    result.grid(row=3,column=1)
    window.mainloop()


window=Tk()
window.geometry('300x400')
menubar=Menu(window)

filemenu=Menu(menubar,tearoff=0)
menubar.add_cascade(label='calculate',menu=filemenu)

series=Menu(filemenu,tearoff=0)
filemenu.add_cascade(label='series',menu=series)
series.add_command(label='example 2-37',command=case37)


window.config(menu=menubar)

window.mainloop()
Rory
  • 661
  • 1
  • 6
  • 15
farzane
  • 1
  • 1

0 Answers0