import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from japanmap import picture
import csv
import numpy as np
#from PIL import Image, ImageTk
root = tk.Tk()
root.title("地図のTkinterへの埋め込み")
root.geometry("1200x600")
fig = plt.figure(figsize=(6, 6), dpi=100)
#plt.imshow(picture(iro_data)) #日本地図の作成
frame = tk.Frame()
frame.pack()
canvas = FigureCanvasTkAgg(fig, master=frame)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
plt.rcParams['figure.figsize'] = 2, 2
DATAFILE = 'C:/Users/hiromi/Desktop/hyaku.csv' #それぞれ変更してください
#DATAFILE = 'C:/Users/Hikyaku/Documents/prj/kotorilabo/201910/hyakumeijo/hyaku.csv'
shirosu=[3,2,1,2,1,1,3,1,1,2,2,1,2,1,2,5,2,1,2,2,2,3,4,2,4,1,2,5,1,1,1,3,4,3,2,1,2,5,1,2,3,2,2,2,1,1,3]#県ごとの城数
seihasu_list=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
iro_list = ['white', 'pink', 'yellow','orange','blue','red']
iro_data = []
data = []
siro = tk.StringVar()
def yomikomi():
datacsv = open(DATAFILE, encoding='shift-jis')
ken=0#どの県を調査しているか
nokori=shirosu[ken]
seihasu_list[ken]=0
for row in csv.reader(datacsv):
data.append(row)
if nokori==0:
ken+=1
nokori=shirosu[ken]
seihasu_list[ken]=0
if row[2]=='1':
seihasu_list[ken]+=1
nokori-=1
def kakikomi():
with open(DATAFILE, 'w', newline = '') as f:
writer = csv.writer(f)
for row in data:
writer.writerow(row)
def hyoji():
iro_data = {i+1: iro_list[seihasu_list[i]] for i in range(0, 47)}
plt.imshow(picture(iro_data))#日本地図の作成
hanrei=tk.Frame(frame, bg="black")
hanrei.pack()
tk.Label(hanrei, text="■一城",font=("",20),fg='pink',bg="black").pack()
tk.Label(hanrei, text="■二城",font=("",20),fg='yellow',bg="black").pack()
tk.Label(hanrei, text="■三城",font=("",20),fg='orange',bg="black").pack()
tk.Label(hanrei, text="■四城",font=("",20),fg='blue',bg="black").pack()
tk.Label(hanrei, text="■五城",font=("",20),fg='red',bg="black").pack()
tk.Label(hanrei, text="■零城",font=("",20),fg='white',bg="black").pack()
tk.Label(hanrei, text="どの城に行きましたか?",font=("",20),fg='black').pack()
tk.Entry(hanrei,textvariable = siro, width = 30).pack() #入力フォームの表示
tk.Button(hanrei,text = "OK", command = seiha).pack()
def koshin():
iro_data = {i+1: iro_list[seihasu_list[i]] for i in range(0, 47)}
plt.imshow(picture(iro_data))
canvas.draw()
def seiha():
print(siro.get())
for i in range(len(data)):
if data[i][0] == siro.get():
data[i][2] = 1
kakikomi()
yomikomi()
koshin()
yomikomi()
hyoji()
tk.mainloop()
コメント
最新を表示する
NG表示方式
NGID一覧