python 中tkinter 实现中国地图展示浙江各地市下属县、区,点击相应区县弹出相关名称

import tkinter as tk
import pandas as pd
import matplotlib.pyplot as plt

# 读取浙江省各地市和下属区县的名称和经纬度数据
data = pd.read_csv('zhejiang_map.csv')

# 定义一个函数,用于在地图上绘制浙江省各地市和下属区县的标记点
def draw_map(data):
    fig, ax = plt.subplots()
    ax.set_aspect('equal')
    ax.axis('off')
    ax.axis('off')
    x, y = data['longitude'], data['latitude']
    for i in range(len(data)):
        if i == 0:
            ax.scatter(x[i], y[i], s=100, color='red', marker='^')
        else:
            ax.scatter(x[i], y[i], s=50, color='blue', marker='o')
    plt.show()

# 创建一个 tkinter 窗口对象
root = tk.Tk()

# 设置窗口大小和位置
root.geometry('600x400+500+200')

# 创建一个标签对象,用于显示地图
label = tk.Label(root, width=600, height=400)
label.pack()

# 创建一个按钮对象,用于触发绘制地图的函数
button = tk.Button(root, text='绘制地图', command=lambda: draw_map(data))
button.pack()

# 运行窗口事件循环,等待用户操作
root.mainloop()

猜你喜欢

转载自blog.csdn.net/ducanwang/article/details/131750019
今日推荐