Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在TKinter上刷新图像_Python_Python 2.7_Tkinter - Fatal编程技术网

Python 如何在TKinter上刷新图像

Python 如何在TKinter上刷新图像,python,python-2.7,tkinter,Python,Python 2.7,Tkinter,我的函数映射更新程序不工作。看来tkinter没有保留对图像的引用。我尝试将引用存储在数组中,我尝试了这里的建议 两者都不起作用 #-----Begin Global Declarations-----# global futureonoff futureonoff = True #-----End Global Declarations-----# #Create a new window window = Tkinter.Tk() window.wm_title("SpaceMass")

我的函数映射更新程序不工作。看来tkinter没有保留对图像的引用。我尝试将引用存储在数组中,我尝试了这里的建议

两者都不起作用

#-----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()
#----开始全局声明-----#
全球未来开放
futureonoff=真
#-----结束全局声明-----#
#创建一个新窗口
window=Tkinter.Tk()
window.wm_标题(“SpaceMass”)
窗几何(“1000x1000”)
window.self=Text(bg='black')
window.self.pack(fill=“both”,expand=True)
#基于ISS位置更新地图
def mapupdater():
全球未来开放
标记列表=[]
timenowforcomputing=strftime(“%Y-%m-%d%H:%m:%S”,gmtime())
iss.compute(timenowforcomputing)
currentlong=iss.sublong
currentlat=iss.sublat
currentlongfloat=浮动(iss.sublong)
currentlatfloat=浮动(iss.子级)
#使用公式1弧度=57.2957795度将弧度转换为度
#TODO学习如何在python中使用pi
currentlongfloat=圆形(currentlongfloat*57.2957795,3)
currentlatfloat=圆形(currentlatfloat*57.2957795,3)
打印(当前长浮点)
打印(当前浮动)
如果futureonoff==真:
FutureIntercenter=0
而FutureIntercenter
在初始化
currentlongfloat
之前,您发布的代码不会运行
currentlongfloat=round(currentlongfloat*57.2957795,3)
。此外,你可能会考虑减少它来重现你的问题。Yea,我把这个问题弄得一团糟。