如何在TKinter上刷新图像

时间:2014-04-21 11:49:27

标签: python python-2.7 tkinter

我的函数mapupdater无效。似乎tkinter没有保留对图像的引用。我尝试将引用存储在一个数组中,我尝试了这里的建议How to update the image of a Tkinter Label widget?

两者都不起作用。

#-----Begin Global Declarations-----#
global futureonoff
futureonoff = True
#-----End Global Declarations-----#

#Create a new window 
window = Tkinter.Tk()
window.wm_title("SpaceMass")
window.geometry("1000x1000")
window.self= Text(bg='black')
window.self.pack(fill="both", expand=True)

#updating map based on ISS location
def mapupdater():
    global futureonoff
    marker_list = []
    timenowforcomputing = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    iss.compute(timenowforcomputing)
    currentlong = iss.sublong 
    currentlat = iss.sublat 
    currentlongfloat= float(iss.sublong)
    currentlatfloat= float(iss.sublat)
    #convert radians to degrees with the equations 1 radian = 57.2957795 degrees
    #TODO Learn how to use pi in python 
    currentlongfloat = round(currentlongfloat*57.2957795, 3)
    currentlatfloat= round(currentlatfloat*57.2957795, 3)
    print(currentlongfloat)
    print(currentlatfloat)
    if futureonoff == True:
        futureintermenter = 0
        while futureintermenter < len(long_list_3_orbits):
            marker_list.append("markers=size:mid|label:F|color:blue|"+str(lat_list_3_orbits[futureintermenter])+","+str(long_list_3_orbits[futureintermenter])+"|")
            futureintermenter = futureintermenter + 1
    marker_list.append("markers=size:mid|label:S|color:red|"+str(currentlatfloat)+","+str(currentlongfloat)+"|")
    toopenupdater = get_static_google_map("mymap2", center="42.950827,-122.108974", zoom=1, imgsize=(500,500), imgformat="gif", maptype="satellite", markers=marker_list)
    #Code from https://stackoverflow.com/questions/6086262/python-3-how-to-retrieve-an-image-from-the-web-and-display-in-a-gui-using-tkint
    uupdater = urllib.urlopen(toopenupdater)
    raw_data_u = uupdater.read()
    u.close()
    b64_data_u = base64.encodestring(raw_data_u)
    imgtoprint = Tkinter.PhotoImage(data=b64_data)

    # from http://www.daniweb.com/software-development/python/threads/79337/putting-an-image-into-a-tkinter-thingy
    # pick an image file you have .bmp  .jpg  .gif.  .png
    # load the file and covert it to a Tkinter image object
    panel1.configure(image = imgtoprint)
    panel1.image = imgtoprint
    #updata map after 30 seconds
    window.after(30000, mapupdater)




def togglemap():
    global futureonoff
    print(futureonoff)
    if futureonoff == True:
        futureonoff = False
    else:
        futureonoff = True
    mapupdater()
    print(futureonoff)

    #text_file.configure(text=testing)
#Info about buttons http://effbot.org/tkinterbook/button.htm
#Parsing code from https://stackoverflow.com/questions/773797/updating-tkinter-labels-in-python
#settings for font, font size, pixel size, of the text in our GUI

#convert radians to degrees with the equations 1 radian = 57.2957795 degrees
#TODO Learn how to use pi in python 
currentlongfloat = round(currentlongfloat*57.2957795, 3)
currentlatfloat= round(currentlatfloat*57.2957795, 3)
if futureonoff == True:
    futureintermenter = 0
    while futureintermenter < len(long_list_3_orbits):
        marker_list.append("markers=size:mid|label:F|color:blue|"+str(lat_list_3_orbits[futureintermenter])+","+str(long_list_3_orbits[futureintermenter])+"|")
        futureintermenter = futureintermenter + 1
marker_list.append("markers=size:mid|label:S|color:red|"+str(currentlatfloat)+","+str(currentlongfloat)+"|")
#places map into GUI
toopen = get_static_google_map("mymap2", center="42.950827,-122.108974", zoom=1, imgsize=(500,500), imgformat="gif", maptype="satellite", markers=marker_list)
#im = PIL.Image.open("mymap2.png")
#imageFile = "mymap2.png"
#Code from https://stackoverflow.com/questions/6086262/python-3-how-to-retrieve-an-image-from-the-web-and-display-in-a-gui-using-tkint
#print(toopen)
u = urllib.urlopen(toopen)
raw_data = u.read()
u.close()
b64_data = base64.encodestring(raw_data)
global imgtoprint
imgtoprint = Tkinter.PhotoImage(data=b64_data)
panel1 = Tkinter.Label(window, image=imgtoprint, bg='black')
panel1.pack(side='top', fill='both', expand='yes')
panel1.place(x=250, y=115)
b = Button(window, text="Browse for XML File", font=("Helvetica", 15), command=fileback, bg = 'black')
b.pack()
b.place(x=425,y=650)
c = Button(window, text="Toggle Orbit Prediction on Map", font=("Helvetica", 15), command=togglemap, bg = 'black')
c.pack()
c.place(x=425,y=850)

mapupdater()
window.mainloop()

0 个答案:

没有答案