def __init__(self, name): self.progressbar_pos = [0, 0] self.progressbar_dir = 'e' self.name = name self.progressbar_on = False self.thread = None self.crossword = Crossword.load(name) # WINDOW CONFIG self.window = tkinter.Tk() self.window.title('Generátor osemsmeroviek') self.window.resizable(False, False) self.window.lift() self.window.focus_force() self.window.bind('<Escape>', lambda e: self.close()) self.width = self.crossword.x_size * 20 + 18 self.height = self.crossword.y_size * 20 + 18 self.canvas = tkinter.Canvas(self.window, height=self.height, width=self.width) self.canvas.pack(side='right') Render.draw_table(self.canvas, self.crossword) # WORD LIST self.word_list = tkinter.Listbox(self.window, width='22') self.word_list.pack(side='top', anchor='n') for word in self.crossword.words: self.word_list.insert('end', word.word) if len(self.crossword.words): Render.draw_letters(self.canvas, self.crossword) tkinter.Button(self.window, text='Zmazať slovo', command=self.delete_selected, width='18').pack(side='top', anchor='n') # SPACER tkinter.LabelFrame(self.window, text='', height='10').pack(side='top') # NEW WORD self.nw_entry = tkinter.Entry(self.window, width='22') self.nw_entry.pack(side='top', anchor='n') self.nw_entry.bind('<Return>', lambda e: self.add_word()) tkinter.Button(self.window, text='Pridať slovo', command=self.add_word, width='18').pack(side='top', anchor='n') # SPACER tkinter.LabelFrame(self.window, text='', height='12').pack(side='top') # GENERATE AND SAVE tkinter.Button(self.window, text='Generovať', command=self.generate, width='18').pack(side='top', anchor='s') self.save_btn = tkinter.Button(self.window, text='Uložiť', command=self.save, width='18', state='disabled') self.save_btn.pack(side='top', anchor='s')
def draw(self, crossword): self.x_size = crossword.x_size self.y_size = crossword.y_size w1 = math.ceil( len(crossword.words) / self.y_size) * 100 + self.x_size * 20 + 40 w2 = len(crossword.solution) * 10 + 40 self.canvas.config(width=w1 if w1 > w2 else w2, height=self.y_size * 20 + 80) self.canvas.delete('all') Render.draw_table(self.canvas, crossword) Render.draw_letters(self.canvas, crossword) Render.draw_words(self.canvas, crossword) self.canvas.create_text(10, self.y_size * 20 + 20, text=crossword.solution_start, anchor='nw', font='Arial 16', tag='solution')