Python Forum
[Tkinter] apply command on every list element
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] apply command on every list element
#7
Make a tiny change to your program to initialize each Entry to the index of the Intvar in Square (line 18). Run the program. See those numbers, they are the numbers you use when you want to work with that square. To convert row/column to these values use the equation:

index = column * 9 + row.

If I want to get the value in row 5, column 7 I call Square[68].get().
If I want to set row 8, column 2 = 5 I call Square[26].set(5)
import tkinter as tk
from tkinter import Entry, IntVar, Tk
fenster = tk.Tk()
 
fenster.geometry("500x540")
fenster.resizable(width=0, height=0)
l=tk.Label(fenster, text="Sudoku Solver")
l["font"]="Arial"
l.place(x=240,y=0)
 
Square = []
def SquareCreate(): 
    for i in range(0, 9):
        for j in range(0,9):
            data = IntVar()
            t = tk.Entry(fenster, textvariable=data, font=("Times New Roman",12))
            t.place(x=i*40+70, y=j*40+80, width=40, height=40)
            data.set(len(Square))
            Square.append(data)
 
def quit():
    fenster.destroy()
             
#Hauptprogramm
SquareCreate()
b=tk.Button(fenster, text="schließen", command = quit)
b.place(x=50,y=450)
print(Square)
fenster.mainloop()
Reply


Messages In This Thread
apply command on every list element - by flash77 - May-12-2020, 06:31 PM
RE: apply command on every list element - by deanhystad - May-14-2020, 10:05 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020