Hi i am trying to print the sum of the numbers that will be written in the entry boxes but I think there is a problem with changing list into int form. I keep getting this error
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Entry'
from tkinter import *
window = Tk()
window.title=("card")
window.geometry('1500x100')
entries = []
def total():
for entry in entries:
global sum
sum = sum int(entry)
e1.insert(0,sum)
for i in range(10):
en = Entry(window)
en.grid(row=1, column=0 i)
entries.append(en)
b1=Button(window,text="dsf",command=total).grid(row=7,column=1)
e1=Entry(window).grid(row=20,column=2)
window.mainloop()
CodePudding user response:
Your code have multiple issues,see code below.
import tkinter as tk #dont use wildcard imports to avoid name conflicts
window = tk.Tk()
window.title=("card")
window.geometry('1500x100')
entries = []
def total():
summa = 0 #dont use reserved names like sum or all
for entry in entries:
summa = int(entry.get())# entrys content as int
e1.delete(0, 'end')#clear entry
e1.insert(0,summa)
for i in range(3):
en = tk.Entry(window)
en.grid(row=1, column=0 i)
entries.append(en)
b1=tk.Button(window,text="dsf",command=total)#split construction
b1.grid(row=7,column=1)#######################from geometry method
e1=tk.Entry(window)
e1.grid(row=20,column=2)
window.mainloop()