Apr-01-2018, 02:34 PM
(This post was last modified: Apr-01-2018, 02:34 PM by Gribouillis.)
This is very nice. I had some problems with the paths to the files, because I'm a linux user, so here are a few changes to handle the paths in a platform-independent way. First I change saveSudoku() to
I suggest to change SudokuSolver_main like so
def saveSUDOKU(self): CHECK = self.checkSUDOKU(self.solution) if CHECK[0] and CHECK[1]: # check if Sudoku is valid and complete filecount = 1 # variable for how many sudoku files are already existing while os.path.isfile(self.path_to("sudoku%s.txt" % filecount)): filecount += 1 sudokuFile = open(self.path_to("sudoku%s.txt" % filecount), 'w') solutionFile = open(self.path_to("solution%s.txt" % filecount), 'w') # ----- create textfiles for sudoku and the solution ----- # for row in range(9): for col in range(9): sudokuFile.write(self.sudoku[row][col]) solutionFile.write(self.solution[row][col]) sudokuFile.write('\n') solutionFile.write('\n') sudokuFile.close() solutionFile.close() self.message_txt.set('Files saved...') else: self.message_txt.set('Sudoku must be valid and complete!')Then at the beginning of the SudokuSolver class
def __init__(self, parent): Frame.__init__(self, parent, name='frame') self.parent = parent self.initUI() self.blankSUDOKU() self.sudokudir = os.path.join(os.getcwd(), 'sudokus') def path_to(self, name): return os.path.join(self.sudokudir, name)You also need to change one line in initSUDOKU()
sudokuFile = open(self.path_to("sudoku%s.txt" % (randint(1, L))))The
print
button does not work, you need to change the callback for this.I suggest to change SudokuSolver_main like so
# SudokuSolver_main.py if __name__ == '__main__': from tkinter import Tk import SudokuSolver_class as Sudokuolver def main(): root = Tk() app = Sudokuolver.SudokuSolver(root) root.mainloop() main()because the child process does not need to import tkinter at all.