所以,我是编程的新手,我现在正在使用带有Tkinter和Canvas的rapsberry pi 3上的Python创建一个交互式地图,供学生对他们在校园周围看到的动物进行编目。我遇到的问题是找到一种方法来创建一个图像,该图像是各个地图上每个人的输入的组合,以显示在这个新地图上。我最终会做的是将这个代码嵌入wordpress php(我已经找到了一个代码)。
我想到的一个可能的事情是将图像保存为postscript文档,然后将该文档用于Image Magick之类的东西,并以某种方式将图像覆盖在彼此的顶部,尽管我不确定它会如何&# 34;更新"
如果有人对python 2.9.7
感兴趣,这是我的交互式地图代码import base64
import Tkinter
import urllib
def getaddress (location, width, height, zoom):
locationnospaces = urllib.quote_plus(location)
address = "http://maps.googleapis.com/maps/api/staticmap?\
center={0}&zoom={1}&size={2}x{3}&format=gif&sensor=false"\
.format(locationnospaces, zoom, width, height)
return address
def getmap (location, width, height, zoom):
address = getaddress(location, width, height, zoom)
urlreader = urllib.urlopen(address)
data = urlreader.read()
urlreader.close()
base64data = base64.encodestring(data)
image = Tkinter.PhotoImage(data=base64data)
return image
def getlabelname():
popup = Tkinter.Toplevel()
popup.title("Rabbit Season")
label = Tkinter.Label(popup, text="Date/Time of Sighting")
label.pack()
labelname = Tkinter.StringVar()
textbox = Tkinter.Entry(popup, textvariable=labelname)
textbox.pack()
textbox.focus_force()
button = Tkinter.Button(popup, text ="Done", command=popup.destroy)
button.pack()
popup.wait_window()
text = labelname.get()
return text
def canvasclick(event):
x,y = event.x, event.y
widget = event.widget
size = 10
widget.create_oval(x-size, y-size, x+size, y+size, width=2)
label = getlabelname()
widget.create_text(x, y+2*size, text=label)
location = "Adelphi University"
width = 640
height = 480
zoom = 16
window = Tkinter.Tk()
window.title(location)
window.minsize(width, height)
window.maxsize(width, height)
mapimage = getmap(location, width, height, zoom)
canvas = Tkinter.Canvas(window, width=width, height=height)
canvas.create_image(0,0,image=mapimage,anchor=Tkinter.NW)
canvas.bind("<Button-1>",canvasclick)
canvas.pack()
window.mainloop()