Advertisement
here2share

# 9x9 Grid of Entries.py

May 15th, 2024
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. # 9x9 Grid of Entries.py
  2.  
  3. import tkinter as tk
  4.  
  5. def load_test():
  6.     global test
  7.     for i in range(9):
  8.         for j in range(9):
  9.             entry_boxes[i][j].delete(0, tk.END)
  10.             entry_boxes[i][j].insert(0, str(test[i][j]))
  11.  
  12. def print_entries():
  13.     entries_list = []
  14.     for i in range(9):
  15.         row_list = []
  16.         for j in range(9):
  17.             try:
  18.                 value = int(entry_boxes[i][j].get())
  19.             except ValueError:
  20.                 value = 0
  21.             row_list.append(value)
  22.         entries_list.append(row_list)
  23.     print(row)
  24.  
  25. root = tk.Tk()
  26. root.title("9x9 Grid of Entry Boxes")
  27.  
  28. entry_boxes = []
  29.  
  30. for i in range(9):
  31.     row_list = []
  32.     for j in range(9):
  33.         entry = tk.Entry(root, width=10)
  34.         entry.grid(row=i, column=j, padx=7, pady=3)
  35.         row_list.append(entry)
  36.     entry_boxes.append(row_list)
  37.  
  38. load_button = tk.Button(root, text="Load Test", command=load_test)
  39. load_button.grid(row=9, column=0, columnspan=9, padx=5, pady=1, sticky="ew")
  40.  
  41. print_button = tk.Button(root, text="Print Entries", command=print_entries)
  42. print_button.grid(row=10, column=0, columnspan=9, padx=5, pady=1, sticky="ew")
  43.  
  44. # Test data
  45. test = [
  46. [3, 25, 6, 8, 30, 11, 6, 25, 9],
  47. [25, 2, 25, 30, 7, 30, 25, 5, 25],
  48. [5, 25, 4, 10, 30, 9, 8, 25, 7],
  49. [25, 30, 13, 2, 7, 5, 7, 30, 25],
  50. [30, 9, 30, 9, 1, 6, 30, 6, 30],
  51. [12, 30, 11, 4, 8, 3, 9, 30, 8],
  52. [5, 25, 8, 9, 30, 12, 4, 25, 7],
  53. [25, 4, 25, 30, 8, 30, 25, 3, 25],
  54. [7, 25, 6, 11, 30, 10, 6, 25, 5]]
  55.  
  56. root.mainloop()
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement