繁体   English   中英

python tkinter pandas 搜索 function 的问题

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM