i am getting this error
Exception in Tkinter callback
Traceback (most recent call last):
File “C:UsersCPanaconda3Libtkinter_init_.py”, line 1948, in call
return self.func(*args)
^^^^^^^^^^^^^^^^
File “C:UsersCPAppDataLocalTempipykernel_127362465764817.py”, line 32, in submit
result_label.config(text=f’Percentage of organic carbon: {percentage:.2f}%’)
^^^^^^^^^^^^^^^^^^^
AttributeError: ‘NoneType’ object has no attribute ‘config’
i was trying to make a calculator of organic matter percentage of soil calculator using tkinter and user defined function.but having problem to show the result in my GUI.the main problem is with the .config()
import tkinter as tk
def calculator_interface():
[root=tk.Tk(className='GUI practice')
label=tk.Label(root,text='Integrated Interface To Collect Data',font=('Times New Roman',8,'bold')).grid(row=0,column=0)
def submit():
b = B_Entry.get()
t = T_Entry.get()
w = W_Entry.get()
# Convert values to float
b_ = float(b)
t_ = float(t)
w_ = float(w)
def per_OC(b_,t_,w_):
def f():
S1=1
V1=float(input("volume of K2Cr2O7(needed in blank): "))
V2=float(input('volume of FeSO4(value of blank titration): '))
S2=(S1*V1)/V2
return S2
B=b_
T=t_
F=f()
W=w_
C= 0.39
percentage_OC=((B-T)*F*C)/W
print('percentage_OC is ',percentage_OC)
percentage = per_OC(b_, t_, w_)
result_label.config(text=f'Percentage of organic carbon: {percentage:.2f}%')
B_Entry.set("")
T_Entry.set("")
W_Entry.set("")
def tgl():
if cheak_but1.get()==1:
print('carbon analysis')
elif cheak_but2.get()==1:
print('nitrogen analysis')
else:
print('discarded')
B_Entry= tk.StringVar()
T_Entry= tk.StringVar()
W_Entry= tk.StringVar()
B_label=tk.Label(root,text='Blank',font=('Times New Roman',10,'normal')).grid(row=1,column=0)
entry1=tk.Entry(root,textvariable=B_Entry,font=('Times New Roman',10,'normal')).grid(row=1,column=1)
T_label=tk.Label(root,text='Titrated value',font=('Times New Roman',10,'normal')).grid(row=2,column=0)
entry2=tk.Entry(root,textvariable=T_Entry,font=('Times New Roman',10,'normal')).grid(row=2,column=1)
W_label=tk.Label(root,text='weight',font=('Times New Roman',10,'normal')).grid(row=3,column=0)
entry3=tk.Entry(root,textvariable=W_Entry,font=('Times New Roman',10,'normal')).grid(row=3,column=1)
sub_but=tk.Button(root,text='enter',command=submit).grid(row=6,column=0)
cheak_but1=tk.IntVar()
cheak_but2=tk.IntVar()
button1=tk.Checkbutton(root,text='carbon',variable=cheak_but1,command=tgl).grid(row=5,column=0)
button2=tk.Checkbutton(root,text='nitrogen',variable=cheak_but2,command=tgl).grid(row=5,column=1)
result_label = tk.Label(root, text='', font=('Times New Roman', 10, 'normal')).grid(row=7, column=0, columnspan=2)
root.mainloop()
calculator_interface()
thamidur rhaman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.