from tkinter import * import random main = Tk() main.geometry('1100x700') main.title('Шибениця') c = Canvas(main, width = 530, height = 600, bg = 'white') c.place(relx = 0.5, rely = 0.05) slova = ["амперметр", "байрактар","атмосфера", "багатство", "батальйон", "біжутерія", "вдячність", "відеоблог", "гомофобія", "гіпербола", "диктатура", "евакуація", "екзорцизм", "забаганка", "заголовок", "іконостас", "кавалерія", "коломийка", "континент", "лоботомія", "люстрація", "маршрутка", "математик", "махінатор", ] shib = Label(main, text = 'Шибениця', font=('Courier', 25, 'bold')) shib.place(relx = 0.16, rely = 0.05) prav = Label(main, text = "Ваша задача: вгадати слово з 9 літер. \n Вгадаєте - виграєте. \n Не вгадаєте - програєте і людина повіситься.", font=('Courier', 12)) prav.place(relx = 0.005, rely = 0.15) def slovo(): sl = random.choice(slova) chst_sl = sl[1:-1] lit_sl = [] for i in chst_sl: lit_sl.append(i) b1 = Label(text = sl[0], font=('Courier', 25, 'bold')) b2 = Label(text = '_', font=('Courier', 25, 'bold')) b3 = Label(text = '_', font=('Courier', 25, 'bold')) b4 = Label(text = '_', font=('Courier', 25, 'bold')) b5 = Label(text = '_', font=('Courier', 25, 'bold')) b6 = Label(text = '_', font=('Courier', 25, 'bold')) b7 = Label(text = '_', font=('Courier', 25, 'bold')) b8 = Label(text = '_', font=('Courier', 25, 'bold')) b9 = Label(text = sl[-1], font=('Courier', 25, 'bold')) alf = 'абвгґдеєжзиіїйклмнопрстуфхцчшщьюя' nb = [1,2,3,4,5,6,7] loss = [] win = [] def litery(h): ind = alf.index(h) nazh = alf[ind] if h in lit_sl: inde = lit_sl(h) nb1 = nb[inde] lit_sl[inde] = '1' def koord(): if nb1 == 1: x1 = 0.03 y1 = 0.4 if nb1 == 2: x1 = 0.08 y1 = 0.4 if nb1 == 3: x1 = 0.13 y1 = 0.4 if nb1 == 4: x1 = 0.18 y1 = 0.4 if nb1 == 5: x1 = 0.23 y1 = 0.4 if nb1 == 6: x1 = 0.28 y1 = 0.4 if nb1 == 7: x1 = 0.33 y1 = 0.4 return x1, y1 x1, y1 = kord() win.append(h) if not h in lit_sl: butt[nazh]['state'] = 'disabled' if h in lit_sl: win.append(h) inde2 = lit_sl.index(h) nb1 = nb[inde2] butt = {} def rozm(a, x, y): butt[a] = Button(main, text = a, width = 3, height = 1, command = litery(a)) butt[a].place(relx = str(x), rely = str(y)) x = 0.05 y = 0.5 for i in alf[0:13]: rozm(i, x, y) x += 0.03 x = 0.05 y = 0.55 for i in alf[13:26]: rozm(i, x, y) x += 0.03 x = 0.05 y = 0.6 for i in alf[26:33]: rozm(i, x, y) x += 0.03 main.mainloop()