python - Labels Aren't Changing -


i'm going post snippet of code, because essentially, same thing.

string = ''  time_calc = tk() time_calc.geometry('500x400') time_calc.title("calculate time") time_calc_frame= frame(time_calc).grid(row=0, column=0)  jul_box = entry(time_calc) jul_box.insert(0, "julian date") jul_box.pack(side = top) jul_box.bind('<return>')  def jd2gd(jd):   global string   jd=jd+0.5   z=int(jd)   f=jd-z   alpha=int((z-1867216.25)/36524.25)   a=z + 1 + alpha - int(alpha/4)    b = + 1524   c = int( (b-122.1)/365.25)   d = int( 365.25*c )   e = int( (b-d)/30.6001 )    dd = b - d - int(30.6001*e) + f    if e<13.5:             mm=e-1    if e>13.5:             mm=e-13    if mm>2.5:             yyyy=c-4716    if mm<2.5:             yyyy=c-4715    months=["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]   daylist=[31,28,31,30,31,30,31,31,30,31,30,31]   daylist2=[31,29,31,30,31,30,31,31,30,31,30,31]    h=int((dd-int(dd))*24)   min =int((((dd-int(dd))*24)-h)*60)   sec=86400*(dd-int(dd))-h*3600-min*60    # calculate fractional year. have leap year?   if (yyyy%4 != 0):             days=daylist2   elif (yyyy%400 == 0):             days=daylist2   elif (yyyy%100 == 0):             days=daylist   else:             days=daylist2    hh = 24.0*(dd % 1.0)   min = 60.0*(hh % 1.0)   sec = 60.0*(min % 1.0)    dd =  dd-(dd%1.0)   hh =  hh-(hh%1.0)   min =  min-(min%1.0)    if hh < 10:     hh = '0%s'%str(int(hh))   else:       hh = int(hh)   if min < 10:     min = '0%s'%str(int(min))   else:       min = int(min)   if sec < 10:     sec = '0%s'%str(int(sec))   else:       sec = int(sec)    string = "%s/%s/%s  %s:%s:%s utc" % (str(int(mm)), str(int(dd)), str(yyyy), str(hh),               str(min), str(sec))   print string   return   def j2ghandler():   jul = float(jul_box.get())    jd2gd(jul)  j2g_button = button(time_calc, text='convert julian\n gregorian', command = j2ghandler, width= 25, pady=5).pack(side=top)  #draw time string on canvas var = stringvar() var.set(string) label = label(time_calc, textvariable=var) label.pack(side=top) 

i know, "snippet". should happen when put in number , click button should, , does, change string "string" behind scenes. can't label update though. i've tried, can see, use stringvar() update label. also, tried doing .update() on end of function didn't work.

any towards matter appreciated. part of application no matter try, can't work.

thanks help.

ps didn't include from tkinter import *, it's redundant , not necessary code.

the parts in comment boxes changed:

##################### tkinter import * ##################### string = ''  time_calc = tk() time_calc.geometry('500x400') time_calc.title("calculate time") time_calc_frame= frame(time_calc).grid(row=0, column=0)  jul_box = entry(time_calc) jul_box.insert(0, "julian date") jul_box.pack(side = top) jul_box.bind('<return>')  def jd2gd(jd):   global string   jd=jd+0.5   z=int(jd)   f=jd-z   alpha=int((z-1867216.25)/36524.25)   a=z + 1 + alpha - int(alpha/4)    b = + 1524   c = int( (b-122.1)/365.25)   d = int( 365.25*c )   e = int( (b-d)/30.6001 )    dd = b - d - int(30.6001*e) + f    if e<13.5:             mm=e-1    if e>13.5:             mm=e-13    if mm>2.5:             yyyy=c-4716    if mm<2.5:             yyyy=c-4715    months=["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]   daylist=[31,28,31,30,31,30,31,31,30,31,30,31]   daylist2=[31,29,31,30,31,30,31,31,30,31,30,31]    h=int((dd-int(dd))*24)   min =int((((dd-int(dd))*24)-h)*60)   sec=86400*(dd-int(dd))-h*3600-min*60    # calculate fractional year. have leap year?   if (yyyy%4 != 0):             days=daylist2   elif (yyyy%400 == 0):             days=daylist2   elif (yyyy%100 == 0):             days=daylist   else:             days=daylist2    hh = 24.0*(dd % 1.0)   min = 60.0*(hh % 1.0)   sec = 60.0*(min % 1.0)    dd =  dd-(dd%1.0)   hh =  hh-(hh%1.0)   min =  min-(min%1.0)    if hh < 10:     hh = '0%s'%str(int(hh))   else:       hh = int(hh)   if min < 10:     min = '0%s'%str(int(min))   else:       min = int(min)   if sec < 10:     sec = '0%s'%str(int(sec))   else:       sec = int(sec)    string = "%s/%s/%s  %s:%s:%s utc" % (str(int(mm)), str(int(dd)), str(yyyy), str(hh),               str(min), str(sec))   print string   ##############   return string   ##############   def j2ghandler():   jul = float(jul_box.get())    #####################   var.set(jd2gd(jul))   #####################  j2g_button = button(time_calc, text='convert julian\n gregorian', command = j2ghandler, width= 25, pady=5).pack(side=top)  #draw time string on canvas var = stringvar() var.set(string) label = label(time_calc, textvariable=var) label.pack(side=top)  ############################## time_calc.mainloop() ############################## 

basically, key make jd2gd return string , use update label variable.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -