在这段python代码中,我使用了一个只允许在输入框中插入整数和空格的验证检查。但是,当将代码重写回array_entry.insert(0, alist)
行的框中时,代码会自行删除。我该如何修复此问题,以便修改后的数组能够在不自我删除的情况下返回到输入框中。提前感谢(:
from tkinter import *
window = Tk()
window.title("Array manipulation GUI")
def int_check_space(value, action):
if action == '1':
if value.isdigit():
return True
elif value == " ":
return True
else:
return False
return True
array_entry = Entry(window, validate="all")
array_entry['validatecommand'] = (array_entry.register(int_check_space),'%S','%d')
array_entry.pack()
def run():
alist = [int(x) for x in array_entry.get().split()]
print(alist)
array_entry.delete(0, END)
array_entry.insert(0, alist)
calculate_button = Button(window,text="Calculate", command=run)
calculate_button.pack()
window.mainloop()
只需删除这些行:
#array_entry.delete(0, END)
#array_entry.insert(END, alist)