TypeError (python tkinter Entry)
this is normal problem:
The normal function is returned None. so this mean in your for loop
in num(n)
function the if you made isn't true so the functions doesn't return z
it's returned as normal function which is None
. so if you want to check that append else
and print out if the if statements doesn't true. like this :
def num(n): for z in range(0,n): y=(first-achieve)*(z/100) if (first-today)==y: return z if today<achieve: z=100 return z else: print('The if statements is not true so the function now returned None')
so if you want to return the z in all statements in else
append return z
so when you call the function every where and every time it's will return int
do:
def num(n): for z in range(0,n): y=(first-achieve)*(z/100) if (first-today)==y: return z if today<achieve: z=100 return z else: return z # if you want to give a message error to user do this: # from tkinter import messagebox # messagebox.showerror('Error', 'the function dosen't returned int')
the final code:
from tkinter import *import tkinterapp=Tk()app.title("progress")app.geometry("800x500+365+120")q={'weigh':100,'goal':75,'now':86} #or 'now':93def bar(): first=int(q['weigh']) achieve=int(q['goal']) today=int(q['now']) def num(n): for z in range(0,n): y=(first-achieve)*(z/100) if (first-today)==y: return z if today<achieve: z=100 return z else: return z # if you want to give a message error to user do this: # from tkinter import messagebox # messagebox.showerror('Error', 'the function dosen't returned int') print(num(101)) rate=int(num(101)/10) for _ in range(1,rate+1): Entry(app,bg="blue",width=4).pack(side=LEFT) for _ in range(rate,10): Entry(app,width=4).pack(side=LEFT)Button(app,text="OK",command=bar).pack()app.mainloop()
Hope this works.