Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 9x9 Grid of Entries.py
- import tkinter as tk
- def load_test():
- global test
- for i in range(9):
- for j in range(9):
- entry_boxes[i][j].delete(0, tk.END)
- entry_boxes[i][j].insert(0, str(test[i][j]))
- def print_entries():
- entries_list = []
- for i in range(9):
- row_list = []
- for j in range(9):
- try:
- value = int(entry_boxes[i][j].get())
- except ValueError:
- value = 0
- row_list.append(value)
- entries_list.append(row_list)
- print(row)
- root = tk.Tk()
- root.title("9x9 Grid of Entry Boxes")
- entry_boxes = []
- for i in range(9):
- row_list = []
- for j in range(9):
- entry = tk.Entry(root, width=10)
- entry.grid(row=i, column=j, padx=7, pady=3)
- row_list.append(entry)
- entry_boxes.append(row_list)
- load_button = tk.Button(root, text="Load Test", command=load_test)
- load_button.grid(row=9, column=0, columnspan=9, padx=5, pady=1, sticky="ew")
- print_button = tk.Button(root, text="Print Entries", command=print_entries)
- print_button.grid(row=10, column=0, columnspan=9, padx=5, pady=1, sticky="ew")
- # Test data
- test = [
- [3, 25, 6, 8, 30, 11, 6, 25, 9],
- [25, 2, 25, 30, 7, 30, 25, 5, 25],
- [5, 25, 4, 10, 30, 9, 8, 25, 7],
- [25, 30, 13, 2, 7, 5, 7, 30, 25],
- [30, 9, 30, 9, 1, 6, 30, 6, 30],
- [12, 30, 11, 4, 8, 3, 9, 30, 8],
- [5, 25, 8, 9, 30, 12, 4, 25, 7],
- [25, 4, 25, 30, 8, 30, 25, 3, 25],
- [7, 25, 6, 11, 30, 10, 6, 25, 5]]
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement