I have created a gui using tkinter in which I created a new window with Toplevel widget and added the widgets to this window such as a entry box , label and button widget . The command attribute of the button widget calls a callback function using the lambda expression such that the gui must not proceed before executing this callback function . But , due to some problem when I press the button widget the callback function is not called .
def toplevel_widget(obj):
def suppress():
try:
if obj.fillna_value.get():
fill_na_value_window.withdraw()
else:
raise Empty_na_value_entry_Error("The textbox can't be left empty!!\nFill any data in it.")
except Empty_na_value_entry_Error as e:
msgbox.showerror("Error",e.msg)
fill_na_value_window=tk.Toplevel(obj)
obj.fillna_value=tk.StringVar()
tk.ttk.Label(fill_na_value_window,text="Enter the value to be inserted").grid(row=1,column=0,padx=10,pady=10)
tk.ttk.Entry(fill_na_value_window,textvariable=obj.fillna_value,width=15).grid(row=1,column=1,padx=10,pady=10)
tk.ttk.Button(fill_na_value_window,text="Ok",command=lambda : suppress,width=10).grid(row=2,columnspan=2)
Cleanser_manual.fillna_toplevel_widget(obj)
val=obj.fillna_value.get()
print("Value : ",val) #here **Value : is printed on screen**
Here the suppress() function is not called even after the button is clicked
suppressfunction object . Don't use lambda, just passsuppressitself (you could uselambda: suppress()but that's just redundant)