我試圖創建的是一個程序,它將首先創建一個熊貓數據框。然後,它將創建一個tkinter窗口,其中包含一個輸入框,一個按鈕和一個文本框。對於下面的代碼,當按下按鈕時,我得到一個輸出,顯示數據框的標題和「搜索」的行。搜索tkinter數據幀
import pandas
from tkinter import *
#creates the dataframe
summer17=pandas.read_excel("summer17.xlsx","list")
window = Tk() #start of the main window
#function that will search the dataframe column "company" for any matches
def search_df():
search_result=summer17[summer17['Company'].str.contains("CAPS")]
t1.insert(END,search_result)
#Creates the entry box
e1_value=StringVar()
e1=Entry(window)
e1.grid(row=0,column=0)
#Creates a button
b1=Button(window,width=10,text='search',command=search_df)
b1.grid(row=0,column=1)
#Creates a text box
t1=Text(window,height=5,width=80)
t1.grid(row=0,column=2)
window.mainloop() #end of the main window
該工程所有和好,不過,我希望用戶能夠輸入一個值到輸入框中,然後按下按鈕並搜索條目。所以我改變功能是
def search_df():
search_result=summer17[summer17['Company'].str.contains(e1_value.get())]
t1.insert(END,search_result)
如果我離開這個空白,它返回整個數據幀(我可能會或可能不會想到)。但是,如果我將CAPS放在輸入框中並按下按鈕,它仍會返回整個數據幀。
我的猜測是,當我從輸入框中獲取值時,有一個變量錯過匹配,但我不知道如何糾正該錯誤。
當心我colunm的名字是公司和你的列名是公司 –
這是夢幻般的,我絕不會想到添加*事件。我想這就是你自學計算機語言所得到的結果。此外,感謝您添加功能,只是推入輸入,併案例=假。這些是我想添加的一些功能,但在優先級列表中較低。 – jon