[英]problem with python tkinter pandas search function
i am trying to make a program that reads EXCEL files using tkinter and pandas but i having trouble with the search function the program works it searchs and all but it says "empty dataframe" and doesn't show the information i am looking for.
[![excel 文件][1]][1]
這是我制作的代碼:
import pandas as pd
from tkinter import *
import tkinter.ttk as ttk
from tkinter.filedialog import *
from tkinter.messagebox import *
import xlrd
import xlwt
fen = Tk()
fen.geometry('320x320')
fen.title("test")
lf1=LabelFrame(fen,text='Informations')
lf1.place(x=10,y=10,width=300,height=300)
Label(lf1,text='fichier excel :').place(x=10,y=20)
Label(lf1,text='Référence :').place(x=10,y=60)
Label(lf1,text='Type :').place(x=20,y=140)
Label(lf1,text='Famille :').place(x=20,y=220)
filo = None
def add() :
global filo
filo=askopenfilename(filetypes=[("EXCEL","*.xlsx")])
if filo != '':
print('you chose a new file')
##search function
def search():
df = pd.read_excel(filo,header=0)
print(df)
print(df.loc[(df['Référence Concernée'] == ref ) & (df['Type du non conformitée']== typ )])
fichier=ttk.Button(lf1,text='Ajouter',command=add)
fichier.place(x=120,y=20)
SearchButton = ttk.Button(lf1,text='search',command = search)
SearchButton.place(x=120,y=250)
ref=Entry(lf1)
ref.place(x=100,y=55)
typ=Entry(lf1,state='disabled')
typ.place(x=100,y=135)
Famille=Entry(lf1,state='disabled')
Famille.place(x=100,y=220)
def r1():
typ.configure(state='normal')
Famille.configure(state='disabled')
def r2():
typ.configure(state='disabled')
Famille.configure(state='normal')
vals = ['A', 'B']
etiqs = ['Managers','techniciens']
varGr = StringVar()
r1=ttk.Radiobutton(lf1, variable=varGr, text=etiqs[0], value=vals[0],command=r1)
r2=ttk.Radiobutton(lf1, variable=varGr, text=etiqs[1], value=vals[1],command=r2)
r1.place(x=10,y=100)
r2.place(x=10,y=180)
[1]: https://i.stack.imgur.com/00UmP.png
基於Entry
的 tkinter 文檔,我猜這就是您想要的:
def search():
df = pd.read_excel(filo,header=0)
print(df)
print(df.loc[(df['Référence Concernée'] == ref.get() ) & (df['Type du non conformitée']== typ.get() )])
即,您需要在您的Entry
對象上調用get()
方法來取回它們當前的字符串值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.