Und gibt es eine Möglichkeit, die Eingabefelder mit einer Schleife der Länge des Arrays zu programmieren? Dass ich nicht für alle Daten im Array ein neues Eingabefeld schreiben muss und es aufgrund der Länge des Arrays individuell ist.
Danke für Ihre Hilfe!
Code: Alles auswählen
from tkinter import*
arrays=Tk()
arrays.title = "Numbers"
numbers = [17, 103, 36, 42, 85, 3, 64, 98, 55, 11]
tbox1 = Entry(arrays, width=10)
tbox1.grid(row=2, column=1, ipady = 5)
tbox2 = Entry(arrays, width=10)
tbox2.grid(row=3, column=1, ipady = 5)
tbox3 = Entry(arrays, width=10)
tbox3.grid(row=4, column=1, ipady = 5)
tbox4 = Entry(arrays, width=10)
tbox4.grid(row=5, column=1, ipady = 5)
tbox5 = Entry(arrays, width=10)
tbox5.grid(row=6, column=1, ipady = 5)
tbox6 = Entry(arrays, width=10)
tbox6.grid(row=7, column=1, ipady = 5)
tbox7 = Entry(arrays, width=10)
tbox7.grid(row=8, column=1, ipady = 5)
tbox8 = Entry(arrays, width=10)
tbox8.grid(row=9, column=1, ipady = 5)
tbox9 = Entry(arrays, width=10)
tbox9.grid(row=10, column=1, ipady = 5)
tbox10 = Entry(arrays, width=10)
tbox10.grid(row=11, column=1, ipady = 5)
def change_array():
numbers[0] = int(tbox1.get())
numbers[1] = int(tbox2.get())
numbers[2] = int(tbox3.get())
numbers[3] = int(tbox4.get())
numbers[4] = int(tbox5.get())
numbers[5] = int(tbox6.get())
numbers[6] = int(tbox7.get())
numbers[7] = int(tbox8.get())
numbers[8] = int(tbox9.get())
numbers[-1] = int(tbox10.get())
new_text = "The new array is"
number_label1.config(new_text)
number_label2.config(numbers)
submit = Button(arrays, text="Submit", width=10, bg = "lightgrey", command = change_array())
submit.grid(row=14, column=1)
arrays.mainloop()