Question Details

No question body available.

Tags

python pandas dataframe

Answers (1)

April 4, 2026 Score: 3 Rep: 149,586 Quality: Medium Completeness: 100%

I can't test your code but I see few mistakes which can make problem.

You have common mistake in command=filterdata(sql). It needs function's name without () and parameters - command=filterdata - and when you will click button then it will use () to execute it. Evetually you may use lambda to create function's name command=lambda:filterdata(sql) but it seems useless because there is another mistake.

Second problem: sql = entryvalue.get() gets data only once - when you start program, before user put any data in Entry. You have to use entryvalue.get() directly inside def filterdata(): and it will be executed every time when you click button - so when there will be already any data in Entry.

There is also third problem: function assigned to command= is executed somewhere in mainloop() and it doesn't know what to do with returned value - return df2. If you need this dataframe later then you have to assign it to global variable. So you need global df2 or you have to use existing global df and use df = ... instead of df2 = ....
But if you need it only to run displaydata(df) then you don't need global.


At this moment it executes filterdata(sql) only once - when you start program - and it assigns result from this function to command=.

result = filterdata(sql)
btnfilter = tk.Button(..., command=result)

I don't know what module sqldf you use but I found this sqldf and it shows sqldf.run(...) instead of sql(...).

Maybe your sql(...) gives None and you have df2 = None and this gives displaydata(None) and this makes problem with AttributeError: 'NoneType' object has no attribute 'columns


def filterdata():
    global df

sql = entryvalue.get() # 13` (built-in function) newdf = sqldf.run(sql) # e.g. SELECT FROM df WHERE A>13 #new_df = pandasql.sqldf(sql) # e.g. SELECT FROM df WHERE A>13 else: newdf = df

output.insert("end", f"Query: {sql}\n") output.insert("end", newdf.tostring()) output.insert("end", "\n---\n")

--- main ---

df = pd.DataFrame( { "A": [11, 12, 13, 14, 15], "B": [21, 22, 23, 24, 25], "C": [31, 32, 33, 34, 35], "D": [41, 42, 43, 44, 45], } )

root = tk.Tk()

filterentry = tk.Entry(root) filterentry.pack()

button = tk.Button(root, text="Filter", command=filtersql) button.pack()

output = tk.Text() output.pack()

root.mainloop()

enter image description here