嗨,我正在嘗試列印將寫入輸入框中的數字的總和,但我認為將串列更改為 int 形式存在問題。我不斷收到此錯誤
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()
uj5u.com熱心網友回復:
您的代碼有多個問題,請參閱下面的代碼。
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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/362004.html
上一篇:tkinter比例滑塊值未顯示
