53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import tkinter as tk
|
|
from tkinter import messagebox
|
|
from Sodoku import Sodoku
|
|
|
|
|
|
class SudokuApp:
|
|
|
|
def __init__(self, master):
|
|
self.master = master
|
|
self.master.title("Sudoku")
|
|
|
|
# Haupt-Frame für das Sudoku erstellen
|
|
self.sudoku_frame = tk.Frame(self.master, bg="black")
|
|
self.sudoku_frame.grid(row=0, column=0, padx=10, pady=10)
|
|
|
|
# 9x9 Gitter von Eingabefeldern erstellen
|
|
self.entries = []
|
|
for i in range(9):
|
|
row_entries = []
|
|
for j in range(9):
|
|
# Jedes Eingabefeld in einen Rahmen einbetten
|
|
frame = tk.Frame(self.sudoku_frame, width=40, height=40)
|
|
frame.grid(row=i, column=j, padx=(2 if j % 3 == 0 else 0, 2), pady=(2 if i % 3 == 0 else 0, 2))
|
|
frame.propagate(False)
|
|
entry = tk.Entry(frame, width=2, justify='center', font=('Arial', 16))
|
|
entry.pack(fill="both", expand=True)
|
|
row_entries.append(entry)
|
|
self.entries.append(row_entries)
|
|
|
|
# Button zum Einlesen der Eingaben
|
|
read_button = tk.Button(self.master, text="Sodoku lösen", command=self.read_sudoku, font=('Arial', 14))
|
|
read_button.grid(row=1, column=0, pady=10)
|
|
|
|
|
|
def read_sudoku(self):
|
|
sodoku = Sodoku()
|
|
|
|
for spalte in range(9):
|
|
for zeile in range(9):
|
|
value = self.entries[zeile][spalte].get()
|
|
sodoku.wert_eintragen(int(value) if value.isdigit() else 0, zeile, spalte)
|
|
|
|
print(sodoku)
|
|
sodoku.loesen()
|
|
|
|
|
|
|
|
# Dieses Skript direkt ausführbar machen
|
|
if __name__ == "__main__":
|
|
root = tk.Tk()
|
|
app = SudokuApp(root)
|
|
root.mainloop()
|