Advertisement
NozdrachevNN

buls

Aug 18th, 2022
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. from random import *
  2. from tkinter import *
  3.  
  4. window = Tk()
  5. window.geometry('250x400')
  6. #window.config(bg = 'hot pink')
  7. window.title('Быки и коровы!')
  8.  
  9. count = 0
  10. words = ['слон', 'кора', 'горб', 'мыло', 'мозг', 'крот', 'соль', 'лось', 'кедр']
  11. answer = choice(words)
  12. otvet = ''
  13.  
  14.  
  15. def Click(event):
  16.     global count
  17.     attempt = ans.get()
  18.     bulls = 0
  19.     cows = 0
  20.     count += 1
  21.     if attempt == answer:
  22.         print('Ты угадал, это', answer)
  23.         print('Количество попыток:', count)
  24.         letter1['text'] = answer[0]
  25.         letter2['text'] = answer[1]
  26.         letter3['text'] = answer[2]
  27.         letter4['text'] = answer[3]
  28.         check.unbind('<Button-1>')
  29.     else:
  30.         if len(attempt) > 4 or len(set(attempt)) < 4:
  31.             attempt = input('Нужно слово из 4 различных букв, '
  32.                             'попробуй еще раз.\n')
  33.         else:
  34.             for i in range(4):
  35.                 if attempt[i] == answer[i]:
  36.                     bulls += 1
  37.                 elif attempt[i] in answer:
  38.                      cows += 1
  39.         print(str(count), '.', 'Быки:', bulls, 'Коровы:', cows, attempt)
  40.  
  41. top = Label(text = 'Отгадай слово!', font = 'Times 26', bg = 'cyan',
  42.             fg = 'dark green')
  43. top.grid(row = 0, column = 0, columnspan = 4, padx = 5, pady = 5)
  44.  
  45. letter1 = Label(text = '*', font = 'Times 18', bg = 'skyblue',
  46.             fg = 'black', width = '2')
  47. letter2 = Label(text = '*', font = 'Times 18', bg = 'DarkOrchid',
  48.             fg = 'black', width = '2')
  49. letter3 = Label(text = '*', font = 'Times 18', bg = 'cadet blue',
  50.             fg = 'black', width = '2')
  51. letter4 = Label(text = '*', font = 'Times 18', bg = 'dark salmon',
  52.             fg = 'black', width = '2')
  53.  
  54. letter1.grid(row = 1, column = 0, padx = 5, pady = 5)
  55. letter2.grid(row = 1, column = 1, padx = 5, pady = 5)
  56. letter3.grid(row = 1, column = 2, padx = 5, pady = 5)
  57. letter4.grid(row = 1, column = 3, padx = 5, pady = 5)
  58.  
  59. question = Label(text = 'Твой вариант:', font = 'Times 12', bg = 'cornsilk',
  60.             fg = 'dark red')
  61. question.grid(row = 2, column = 0, columnspan = 4, padx = 5, pady = 5)
  62. ans = Entry(text = '', font = 'Times 12', bg = 'goldenrod')
  63. ans.grid(row = 3, column = 0, columnspan = 4, padx = 5, pady = 5)
  64. check = Button(text = 'Проверить!', font = 'Times 16', fg = 'maroon')
  65. check.grid(row = 4, column = 0, columnspan = 4, padx = 5, pady = 5)
  66. bottom_text = Label(text = otvet, font = 'Times 12',
  67.                     bg = 'hot pink')
  68. bottom_text.grid(row = 5, column = 0, columnspan = 4, padx = 5, pady = 5)
  69. check.bind('<Button-1>', Click)
  70.  
  71. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement