1

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.

[![the excel file][1]][1]

this is the code i made:

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.sstatic.net/00UmP.png
2
  • It looks like typ and ref are not dtypes that pandas will understand so is == typ going to work? Should it maybe be something like == typ.value? It's hard to know what Entry is because you import * which is not a good idea. Commented Aug 6, 2020 at 14:24
  • Also for debugging maybe rather than print(df) try print(df[[['Référence Concernée', 'Type du non conformitée']]) and also print(df[[['Référence Concernée', 'Type du non conformitée']].dtypes) Commented Aug 6, 2020 at 14:26

1 Answer 1

1

Based on the tkinter docs for Entry I would guess this is what you want:

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() )])

i.e. you need to call the get() method on your Entry objects to get back their current string values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.