在tkinter中创建一个用于显示地图的简单应用程序

2024-04-26 22:22:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新手

我有一个程序,把CSV作为输入,包含出口的地理位置, 在地图上显示,保存为HTML。在

我的csv格式:

outlet_code   Latitude    Longitude
 100           22.564      42.48
 200           23.465      41.65
 ...       and so on        ...

下面是我的python代码,用于获取这个CSV并将其放到地图上。在

^{pr2}$

这将显示map_osm

另一种方法是将map_osm另存为HTML

map_osm.save('path/map_1.html')

我要找的是一个图形用户界面,它可以做同样的事情。在

即提示用户输入CSV,然后执行下面的代码并显示结果 或者至少把它保存在一个地方。在

任何线索都会有帮助的


Tags: csv代码程序maphtmlosm格式地图
1条回答
网友
1楼 · 发布于 2024-04-26 22:22:30

如果您提供了您试图为问题的GUI部分编写的任何代码,那么您的问题会得到更好的答复。我知道(以及其他在你的评论上发表文章的人)tkinter有很好的文档记录,有无数的教程网站和YouTube视频。在

但是,如果您尝试过使用tkinter编写代码,但是不明白发生了什么,我已经编写了一个小的基本示例,说明如何编写一个GUI,该GUI将打开一个文件并将每一行打印到控制台。在

这不会正确回答你的问题,但会给你指明正确的方向。在

这是一个非OOP版本,从您现有的代码来看,您可能会更好地理解它。在

# importing tkinter as tk to prevent any overlap with built in methods.
import tkinter as tk
# filedialog is used in this case to save the file path selected by the user.
from tkinter import filedialog

root = tk.Tk()
file_path = ""

def open_and_prep():
    # global is needed to interact with variables in the global name space
    global file_path
    # askopefilename is used to retrieve the file path and file name.
    file_path = filedialog.askopenfilename()

def process_open_file():
    global file_path
    # do what you want with the file here.
    if file_path != "":
        # opens file from file path and prints each line.
        with open(file_path,"r") as testr:
            for line in testr:
                print (line)

# create Button that link to methods used to get file path.
tk.Button(root, text="Open file", command=open_and_prep).pack()
# create Button that link to methods used to process said file.
tk.Button(root, text="Print Content", command=process_open_file).pack()

root.mainloop()

通过这个例子,您应该能够理解如何在tkinter GUI中打开文件并处理它。在

更多OOP选项:

^{pr2}$

相关问题 更多 >