Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas
- import matplotlib.pyplot as plot
- from matplotlib.font_manager import FontProperties
- from tkinter import *
- from tkinter import filedialog
- import matplotlib
- from PIL import Image,ImageTk
- root = Tk()
- root.title('第八週GUI')
- root.state("zoomed")
- path = ''
- names = []
- cnt = []
- money = []
- def main1():
- global names
- st = ''
- for name in names:
- st = st + name + '\n'
- var.set(st)
- def main2():
- global money
- st = ''
- for m in money:
- st = st + str(m) + '\n'
- var.set(st)
- def func2():
- global path
- path = filedialog.askopenfilename(initialdir = "/",title = "Select file")
- plot.rcParams['font.sans-serif'] = ['Microsoft JhengHei']
- plot.rcParams['axes.unicode_minus'] = False
- data = pandas.read_csv(path)
- global names
- global cnt
- global money
- for index, row in data.iterrows():
- if row['產業別'] in names:
- name = names.index(row['產業別'])
- cnt[name] += 1
- money[name] += row['營業收入-當月營收']
- else:
- names.append(row['產業別'])
- cnt.append(1)
- money.append(row['營業收入-當月營收'])
- plot.figure(figsize = [10,10])
- plot.barh(range(len(names)), money)
- plot.yticks(range(len(names)), names)
- plot.savefig('./bar.png')
- plot.figure(figsize = [10,10])
- plot.pie(money, labels=names)
- plot.title("當月營收佔比")
- plot.axis('equal')
- plot.savefig('./pie.png')
- var2.set(path)
- def bar():
- global myImage
- myImage = ImageTk.PhotoImage(Image.open('./bar.png').resize((500, 500), Image.ANTIALIAS))
- myLabel = Label(image = myImage).place(x=200, y=20, anchor='nw')
- def pie():
- global myImage
- myImage = ImageTk.PhotoImage(Image.open('./pie.png').resize((500, 500), Image.ANTIALIAS))
- myLabel = Label(image = myImage).place(x=200, y=20, anchor='nw')
- btn = Button(root, text='主要欄位1',command=main1).place(x=20, y=20, anchor='nw')
- btn1 = Button(root, text='主要欄位2',command=main2).place(x=20, y=70, anchor='nw')
- var = StringVar()
- label = Label(root, textvariable=var,).place(x=20, y=120, anchor='nw')
- var2 = StringVar()
- labe2 = Label(root, textvariable=var2,).place(x=120, y=600, anchor='nw')
- btn2 = Button(root, text='選檔案',command=func2).place(x=20, y=600, anchor='nw')
- btn3 = Button(root, text='長條圖',command=bar).place(x=300, y=650, anchor='nw')
- btn4 = Button(root, text='圓餅圖',command=pie).place(x=500, y=650, anchor='nw')
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement