這個gui大部分都正常,但是標簽頁里想要顯示排名,按了按鈕卻沒有反應,求助
(以科幻為例,一共8個標簽,不知道是不是背景圖的問題)
from tkinter import *
from PIL import Image,ImageTk
import pandas as pd
from pandas import DataFrame
from pandas import Series
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['KaiTi']
biaoge= pd.read_excel('大作業.xlsx','Sheet1')
def kehuan():
kehuan1=biaoge[biaoge['型別']=='科幻']
kehuan=kehuan1['名稱']
entry.delete(0,END)
entry.insert(0,kehuan)
def create1():
top1 = Toplevel()
top1.title('前100名標簽比例')
top1.geometry('400x300')
canvas =Canvas(top1, width=400,height=300,bd=0, highlightthickness=0)
imgpath = 'bintu.gif'
img = Image.open(imgpath)
photo = ImageTk.PhotoImage(img)
canvas.create_image(200,150,image=photo)
canvas.grid()
top1.mainloop()
def create2():
top = Toplevel()
top.title('Bangumi動漫標簽')
top.geometry('400x500')
canvas =Canvas(top, width=400,height=500,bd=0, highlightthickness=0)
imgpath = 'bj.gif'
img = Image.open(imgpath)
photo = ImageTk.PhotoImage(img)
canvas.create_image(0,0,image=photo)
canvas.grid()
entry=Entry(top,highlightthickness =2)
entry.grid()
canvas.create_window(200, 300, width=200, height=300,window=entry)
count=0
l1=['科幻','治愈','熱血','青春','輕小說','奇幻','搞笑','童年']
l2=['kehuan','zhiyu','rexue','qinchun','qingxiaoshuo','qihuan','gaoxiao','tongnian']
for i in range(2):
for j in range(4):
count+=1
e1 = Button(top,text=str(l1[count-1]),fg='chocolate',width=9,bg='linen',command=l2[count-1])
e1.grid()
canvas.create_window(100*j, 100*i, width=80, height=40,window=e1,anchor=N+W)
top.mainloop()
root=Tk()
root.title('Bangumi動漫簡要排行')
root.geometry('460x200')
canvas =Canvas(root, width=460,height=200,bd=0, highlightthickness=0)
imgpath = 'bj.gif'
img = Image.open(imgpath)
photo = ImageTk.PhotoImage(img)
canvas.create_image(0,0,image=photo)
canvas.grid()
lbl1=Label(root,text='Bangumi動漫',fg='white',bg='gray',font=('楷體',30),bd=0).place(x=120,y=20)
lbl2=Label(root,text='簡要排行',fg='white',bg='gray',font=('楷體',15),bd=0).place(x=230,y=70)
Button(root, width=20,text='前100名標簽比例',font='宋體',command=create1).place(x=10,y=120)
Button(root,width=20,text='標簽排行索引',font='宋體',command=create2).place(x=240,y=120)
root.mainloop()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/33142.html
上一篇:PYQT5 關于拉伸怎么改?
