在Python中显示Google Map API Tkinter窗口
您好我正在使用Python中的Google Map API。我正在使用可在此处找到的源代码website在Python中显示Google Map API Tkinter窗口
此代码在编译时生成一个'htm'文件,显示放置在地图上的标记的Google Map。
所以我创建了如下图所示窗口框架:
from Tkinter import * # order seems to matter: import Tkinter first
import Image, ImageTk # then import ImageTk
class MyFrame(Frame):
def __init__(self, master, im):
Frame.__init__(self, master)
self.caption = Label(self, text="Some text about the map")
self.caption.grid()
self.image = ImageTk.PhotoImage(im) # <--- results of PhotoImage() must be stored
self.image_label = Label(self, image=self.image, bd=0) # <--- will not work if 'image = ImageTk.PhotoImage(im)'
self.image_label.grid()
self.grid()
im = Image.open("test.html") # read map from disk
# or you could use the PIL image you created directly via option 2 from the URL request ...
mainw = Tk()
mainw.frame = MyFrame(mainw, im)
mainw.mainloop()
并与窗框我想在窗框显示谷歌地图的“HTM”的形象。
htm图像pymaps产生的不是图像,它是一个html文件。基本上是一个小网页。要显示它,你必须呈现html。我知道TkInter的唯一html渲染器是TkHTML,尽管我从未使用它,所以它可能不支持您的html文件使用的所有javascript。
你会好得多完全下降的Tkinter并切换到一个更现代的部件工具箱如wxPython的具有内置的HTML渲染。你可以看到HTML文档中的wxPython here。如果你的系统上有GTK,我已经成功地使用了pywebkitgtk。
但是,你需要渲染这个框架的具体内容?如果你只是想从python打开文件,你可以使用内建库中的webbrowser来用你的默认浏览器打开它。
import webbrowser
webbrowser.open('test.htm')
就是这样。
嗨Narcolei感谢您对此问题的建议。我决定使用wxPython,主要想法是显示从网站源代码创建的googlem地图,并使用它生成的html文件,并将其显示在框架中以便在浏览器中查看而不是查看它。 从我试图实现的想法来看,你认为可以在框架中而不是在Web浏览器中查看谷歌地图? 在此先感谢。 – user678252 2011-03-27 21:58:14
什么问题? – 2011-03-26 20:22:52