{"id":284884,"date":"2017-04-12T19:35:04","date_gmt":"2017-04-12T15:35:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284884"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284884","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0430\u043f\u0435\u0440\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u043e\u0434\u0443\u043b\u044f Tkinter"},"content":{"rendered":"<p>\u0414\u0435\u043d\u044c \u0434\u043e\u0431\u0440\u044b\u0439. \u041f\u043e\u0447\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0441\u044f \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u0432\u043e\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0433\u0440\u044b. \u0421\u043f\u0443\u0441\u0442\u044f \u043f\u043e\u043b \u0433\u043e\u0434\u0430 <s>\u043b\u0435\u043d\u0438\u0432\u043e\u0433\u043e<\/s> \u043a\u0440\u043e\u043f\u043e\u0442\u043b\u0438\u0432\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u044f \u0440\u0435\u0448\u0438\u043b\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043f\u0435\u0440\u0430. \u042f\u0437\u044b\u043a\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d Python, \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 tkinter, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a \u0443\u0436\u0435 \u0438\u043c\u0435\u043b\u0441\u044f \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c. \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0441\u043a\u043e\u0440\u0435\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u0435\u0440\u0430\u043c, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0442\u0430\u043a \u0432\u0441\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e \u043a\u043e\u0434\u0430 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u044b.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u0435\u0442\u043a\u0430. \u0421\u0430\u043c\u043e\u0435 \u0432\u044b\u0433\u043e\u0434\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u044f:<\/p>\n<pre><code class=\"python\">class pole(object): #\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u041a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u044f, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0441\u044f \u043e\u0442 Object     def __init__(self,master,row, column): #\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044f. master - \u043e\u043a\u043d\u043e Tk().         self.button = Button(master, text = '   ') #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 'button'         self.mine = False #\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043c\u0438\u043d\u044b \u0432 \u043f\u043e\u043b\u0435         self.value = 0 #\u041a\u043e\u043b-\u0432\u043e \u043c\u0438\u043d \u0432\u043e\u043a\u0440\u0443\u0433         self.viewed = False #\u041e\u0442\u043a\u0440\u044b\u0442\u043e\/\u0437\u0430\u043a\u0440\u044b\u0442\u043e \u043f\u043e\u043b\u0435         self.flag = 0 #0 - \u0444\u043b\u0430\u0433\u0430 \u043d\u0435\u0442, 1 - \u0444\u043b\u0430\u0433 \u0441\u0442\u043e\u0438\u0442, 2 - \u0441\u0442\u043e\u0438\u0442 &quot;?&quot;         self.around = [] #\u041c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u043a\u043b\u0435\u0442\u043e\u043a         self.clr = 'black' #\u0426\u0432\u0435\u0442 \u0442\u0435\u043a\u0441\u0442\u0430         self.bg = None #\u0426\u0432\u0435\u0442 \u0444\u043e\u043d\u0430         self.row = row #\u0421\u0442\u0440\u043e\u043a\u0430         self.column = column #\u0421\u0442\u043e\u043b\u0431\u0435\u0446 <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u0433\u0440\u044b:<\/p>\n<pre><code class=\"python\">settings = Tk() #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u043a\u043d\u043e settings.title('\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438') #\u041f\u0438\u0448\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u043a\u043d\u0430 settings.geometry('200x150') #\u0417\u0430\u0434\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 mineText = Text(settings, width = 5, height = 1) #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u044f \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f mineLabe = Label(settings, height = 1, text = '\u0411\u043e\u043c\u0431\u044b:') highText = Text(settings, width = 5, height = 1) highLabe = Label(settings, height = 1, text = '\u0428\u0438\u0440\u0438\u043d\u0430:') lenghtText = Text(settings, width = 5, height = 1) lenghtLabe = Label(settings, height = 1, text = '\u0412\u044b\u0441\u043e\u0442\u0430:') mineBut = Button(settings, text = '\u041d\u0430\u0447\u0430\u0442\u044c:', command = bombcounter) #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443 mineBut.place(x = 70, y = 90)  #\u0420\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u044d\u0442\u043e \u0432\u0441\u0435 mineText.place(x = 75, y = 5) mineLabe.place(x = 5, y = 5) highText.place(x = 75, y = 30) highLabe.place(x = 5, y = 30) lenghtText.place(x = 75, y = 55) lenghtLabe.place(x = 5, y = 55) settings.mainloop()  <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0435 \u0432\u043e\u0442 \u043e\u043a\u043d\u043e:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/cc2\/732\/f26\/cc2732f26c87430c9f63373b74049c66.png\" alt=\"image\" \/><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e bombcounter <\/p>\n<pre><code class=\"python\">def bombcounter():      global bombs      if mineText.get('1.0', END) == '\\n': #\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430         bombs = 10 #\u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0435\u0442, \u0442\u043e \u043f\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 \u043a\u043e\u043b-\u0432\u043e \u0431\u043e\u043c\u0431 - 10     else:         bombs = int(mineText.get('1.0', END)) #\u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0441\u0442 \u0435\u0441\u0442\u044c, \u0442\u043e \u044d\u0442\u043e \u0438 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043b-\u0432\u043e \u0431\u043e\u043c\u0431     if highText.get('1.0', END) == '\\n':         high = 9     else:         high = int(highText.get('1.0', END))     if lenghtText.get('1.0', END) == '\\n':         lenght = 9     else:         lenght = int(lenghtText.get('1.0', END))     game(high,lenght) #\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0438\u0433\u0440\u0443, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u043b\u0435\u0439 <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0433\u0440\u044b:<\/p>\n<pre><code class=\"python\">def game(high,lenght): #\u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f     root = Tk()      root.title('\u0421\u0430\u043f\u0435\u0440')      global buttons     global mines     global flags     flags = [] #\u041c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432 \u0441\u0435\u0431\u0435 \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0441\u0442\u043e\u044f\u0442 \u0444\u043b\u0430\u0436\u043a\u0438     mines = [] #\u041c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432 \u0441\u0435\u0431\u0435 \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u043b\u0435\u0436\u0430\u0442 \u043c\u0438\u043d\u044b     buttons = [[pole(root,j,i) for i in range(high)] for j in range(lenght)] #\u0414\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u0435\u0436\u0430\u0442 \u043f\u043e\u043b\u044f     for i in range(len(buttons)): #\u0426\u0438\u043a\u043b \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c         for j in range(len(buttons[i])): #\u0426\u0438\u043a\u043b \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0441\u0442\u0440\u043e\u043a\u0438             buttons[i][j].button.grid(column = j, row = i, ipadx = 7, ipady = 1) #\u0420\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u043c \u0432\u0441\u0435 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 grid             buttons[i][j].button.bind('&lt;Button-1&gt;', buttons[i][j].view) #\u0411\u0438\u043d\u0434\u0438\u043c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0435\u0442\u043a\u0438             buttons[i][j].button.bind('&lt;Button-3&gt;', buttons[i][j].setFlag) #\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0444\u043b\u0430\u0436\u043a\u0430             buttons[i][j].setAround() #\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 self.around     buttons[0][0].button.bind('&lt;Control-Button-1&gt;', cheat) #\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0432\u0438\u0448 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f     root.resizable(False,False) #\u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430     root.mainloop() <\/code><\/pre>\n<p>  \u0423 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0446\u0435\u043b\u044b\u0445 \u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 .setAround():<\/p>\n<pre><code class=\"python\">    def setAround(self):         if self.row == 0:             self.around.append([self.row+1,self.column])             if self.column == 0:                 self.around.append([self.row,self.column+1])                 self.around.append([self.row+1,self.column+1])             elif self.column == len(buttons[self.row])-1:                 self.around.append([self.row,self.column-1])                 self.around.append([self.row+1,self.column-1])             else:                 self.around.append([self.row,self.column-1])                 self.around.append([self.row,self.column+1])                 self.around.append([self.row+1,self.column+1])                 self.around.append([self.row+1,self.column-1])         elif self.row == len(buttons)-1:             self.around.append([self.row-1,self.column])             if self.column == 0:                 self.around.append([self.row,self.column+1])                 self.around.append([self.row-1,self.column+1])             elif self.column == len(buttons[self.row])-1:                 self.around.append([self.row,self.column-1])                 self.around.append([self.row-1,self.column-1])             else:                 self.around.append([self.row,self.column-1])                 self.around.append([self.row,self.column+1])                 self.around.append([self.row-1,self.column+1])                 self.around.append([self.row-1,self.column-1])         else:             self.around.append([self.row-1,self.column])             self.around.append([self.row+1,self.column])             if self.column == 0:                 self.around.append([self.row,self.column+1])                 self.around.append([self.row+1,self.column+1])                 self.around.append([self.row-1,self.column+1])             elif self.column == len(buttons[self.row])-1:                 self.around.append([self.row,self.column-1])                 self.around.append([self.row+1,self.column-1])                 self.around.append([self.row-1,self.column-1])             else:                 self.around.append([self.row,self.column-1])                 self.around.append([self.row,self.column+1])                 self.around.append([self.row+1,self.column+1])                 self.around.append([self.row+1,self.column-1])                 self.around.append([self.row-1,self.column+1])                 self.around.append([self.row-1,self.column-1]) <\/code><\/pre>\n<p>  \u0412\u0441\u0435, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u044d\u0442\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 self.around. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u0440\u043e\u0449\u0435, \u044f \u043f\u0440\u0438\u043c\u0443 \u0438\u0445 \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<p>  \u041f\u0438\u0448\u0435\u043c view()<\/p>\n<pre><code class=\"python\">    def view(self,event):         if mines == []: #\u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0438             seter(0,self.around,self.row,self.column) #\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u0438\u043d\u044b         if self.value == 0: #\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0446\u0432\u0435\u0442\u0430. \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u0434\u043b\u044f 6,7 \u0438 8, \u043d\u043e \u0443 \u043c\u0435\u043d\u044f \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u044f             self.clr = 'yellow'             self.value = None             self.bg = 'lightgrey'         elif self.value == 1:             self.clr = 'green'         elif self.value == 2:             self.clr = 'blue'         elif self.value == 3:             self.clr = 'red'         elif self.value == 4:             self.clr = 'purple'                  if self.mine and not self.viewed and not self.flag: #\u0415\u0441\u043b\u0438 \u0432 \u043a\u043b\u0435\u0442\u043a\u0435 \u0435\u0441\u0442\u044c \u043c\u0438\u043d\u0430, \u043e\u043d\u0430 \u0435\u0449\u0435 \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0430 \u0438 \u043d\u0430 \u043d\u0435\u0439 \u043d\u0435\u0442 \u0444\u043b\u0430\u0433\u0430             self.button.configure(text = 'B', bg = 'red') #\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u0447\u0442\u043e \u0442\u0443\u0442 \u0435\u0441\u0442\u044c \u043c\u0438\u043d\u0430             self.viewed = True #\u0413\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043a\u043b\u0435\u0442\u043a\u0430 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0430             for q in mines:                 buttons[q[0]][q[1]].view('&lt;Button-1&gt;') #\u042f \u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u0443\u0434\u0443 \u0432\u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0412\u0421\u0415 \u043c\u0438\u043d\u044b             lose() #\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u043a\u043d\u043e \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u0430                  elif not self.viewed and not self.flag: #\u0415\u0441\u043b\u0438 \u043c\u0438\u043d\u044b \u043d\u0435\u0442, \u043a\u043b\u0435\u0442\u043a\u0430 \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0430 \u0438 \u0444\u043b\u0430\u0433 \u043d\u0435 \u0441\u0442\u043e\u0438\u0442             self.button.configure(text = self.value, fg = self.clr, bg = self.bg) #\u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432 \u0442\u0435\u043a\u0441\u0442 \u043f\u043e\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435             self.viewed = True             if self.value == None: #\u0415\u0441\u043b\u0438 \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0442 \u043c\u0438\u043d                 for k in self.around:                     buttons[k[0]][k[1]].view('&lt;Button-1&gt;') #\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0432\u043e\u043a\u0440\u0443\u0433  <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a. \u0421\u0435\u0439\u0447\u0430\u0441 \u0443 \u043d\u0430\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438: \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u043a\u043b\u0435\u0442\u043a\u0438, \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 around, \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0433\u0440\u044b \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0441\u0447\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0438 \u043a\u043e\u043b-\u0432\u0430 \u043c\u0438\u043d. \u041d\u043e \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043c\u0438\u043d. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f:<\/p>\n<pre><code class=\"python\">def seter(q, around,row,column): #\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u043e\u043b\u0435\u0439 \u0432\u043e\u043a\u0440\u0443\u0433 \u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043d\u0430\u0436\u0430\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f     if q == bombs: #\u0415\u0441\u043b\u0438 \u043a\u043e\u043b-\u0432\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0431\u043e\u043c\u0431 = \u043a\u043e\u043b-\u0432\u0443 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0445         for i in range(len(buttons)): #\u0428\u0430\u0433\u0430\u0435\u043c \u043f\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c             for j in range(len(buttons[i])): #\u0428\u0430\u0433\u0430\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u044f\u043c \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 i                 for k in buttons[i][j].viewAround(): #\u0428\u0430\u0433\u0430\u0435\u043c \u043f\u043e \u043f\u043e\u043b\u044f\u043c \u0432\u043e\u043a\u0440\u0443\u0433 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f j                     if buttons[k[0]][k[1]].viewMine(): #\u0415\u0441\u043b\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 k \u043c\u0438\u043d\u0430                         buttons[i][j].setValue(buttons[i][j].viewValue()+1) #\u0422\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f j         return     a = choice(buttons) #\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443     b = choice(a) #\u0420\u0430\u043d\u0434\u043e\u043c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435     if [buttons.index(a),a.index(b)] not in mines and [buttons.index(a),a.index(b)] not in around and [buttons.index(a),a.index(b)] != [row,column]: #\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u043d\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u043b\u043e\u0441\u044c \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u0438, \u0447\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u043c \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043d\u0430\u0436\u0430\u043b\u0438 (\u0438\u043b\u0438 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u043c \u0435\u0435 \u043f\u043e\u043b\u0435\u043c)         b.setMine() #\u0421\u0442\u0430\u0432\u0438\u043c \u043c\u0438\u043d\u0443         mines.append([buttons.index(a),a.index(b)]) #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432          seter(q+1,around,row,column) #\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0449\u0438\u043a, \u0441\u043a\u0430\u0437\u0430\u0432, \u0447\u0442\u043e \u043e\u0434\u043d\u0430 \u043c\u0438\u043d\u0430 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c     else:         seter(q,around,row,column) #\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0449\u0438\u043a \u0435\u0449\u0435 \u0440\u0430\u0437 <\/code><\/pre>\n<p>  \u0418 \u0432\u0442\u043e\u0440\u0430\u044f \u0432\u0430\u0436\u043d\u0430\u044f \u0434\u043b\u044f \u043d\u0430\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f: setValue()<\/p>\n<pre><code class=\"python\">    def setValue(self,value):         self.value = value <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c. \u0418\u0433\u0440\u0430 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441, \u043d\u043e \u0431\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0444\u043b\u0430\u0436\u043a\u0430 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0431\u0435\u0434\u044b\/\u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0448\u0430. \u0422\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0444\u043b\u0430\u0436\u043a\u0430:<\/p>\n<pre><code class=\"python\">    def setFlag(self,event):         if self.flag == 0 and not self.viewed: #\u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u0435 \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u043e \u0438 \u0444\u043b\u0430\u0433\u0430 \u043d\u0435\u0442             self.flag = 1 #\u0421\u0442\u0430\u0432\u0438\u043c \u0444\u043b\u0430\u0433             self.button.configure(text = 'F', bg = 'yellow') #\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0444\u043b\u0430\u0433             flags.append([self.row,self.column]) #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0444\u043b\u0430\u0433\u043e\u0432         elif self.flag == 1: #\u0415\u0441\u043b\u0438 \u0444\u043b\u0430\u0433 \u0441\u0442\u043e\u0438\u043c             self.flag = 2 #\u0421\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 '?'             self.button.configure(text = '?', bg = 'blue') #\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0435\u0433\u043e             flags.pop(flags.index([self.row,self.column])) #\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0444\u043b\u0430\u0433 \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0444\u043b\u0430\u0433\u043e\u0432         elif self.flag == 2: #\u0415\u0441\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441             self.flag = 0 #\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0444\u043b\u0430\u0433\u0430             self.button.configure(text = '   ', bg = 'white') #\u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u0443\u0441\u0442\u043e\u0442\u0443         if sorted(mines) == sorted(flags) and mines != []: #\u0435\u0441\u043b\u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0444\u043b\u0430\u0433\u043e\u0432 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u043c\u0438\u043d             winer() #\u0421\u043e\u043e\u0431\u0449\u0430\u0435\u043c \u043e \u043f\u043e\u0431\u0435\u0434\u0435 <\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438 lose() \u0438 winer() \u043f\u0440\u043e\u0441\u0442\u044b \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0439. \u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0443\u0436\u043d\u043e, \u043d\u0430\u043f\u0438\u0448\u0443 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>  \u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/973\/36a\/7f7\/97336a7f79854963afae096e03bd106e.png\" alt=\"image\" \/><\/div>\n<p>  \u0421\u0432\u043e\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043a\u0440\u0438\u0442\u0438\u043a\u0443 \u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u044b, \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c, \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u0438 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/326358\/\"> https:\/\/habrahabr.ru\/post\/326358\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u0435\u043d\u044c \u0434\u043e\u0431\u0440\u044b\u0439. \u041f\u043e\u0447\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0441\u044f \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u0432\u043e\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0433\u0440\u044b. \u0421\u043f\u0443\u0441\u0442\u044f \u043f\u043e\u043b \u0433\u043e\u0434\u0430 <s>\u043b\u0435\u043d\u0438\u0432\u043e\u0433\u043e<\/s> \u043a\u0440\u043e\u043f\u043e\u0442\u043b\u0438\u0432\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u044f \u0440\u0435\u0448\u0438\u043b\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043f\u0435\u0440\u0430. \u042f\u0437\u044b\u043a\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u044b\u043b \u0432\u044b\u0431\u0440\u0430\u043d Python, \u043c\u043e\u0434\u0443\u043b\u0435\u043c \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 tkinter, \u043f\u043e\u0442\u043e\u043c\u0443 \u043a\u0430\u043a \u0443\u0436\u0435 \u0438\u043c\u0435\u043b\u0441\u044f \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c. \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0441\u043a\u043e\u0440\u0435\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u0435\u0440\u0430\u043c, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0442\u0430\u043a \u0432\u0441\u0435 \u0437\u043d\u0430\u0435\u0442\u0435, \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e \u043a\u043e\u0434\u0430 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u044b.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284884","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284884"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284884\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}