Advertisement
k1alo

Крестики-Нолики final

Dec 15th, 2023 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.91 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. current_player = "X"
  4.  
  5. def fun1():
  6.     global current_player
  7.     button_x1_y1["text"] = current_player
  8.     check()
  9.     if current_player == 'X':
  10.         current_player = '0'
  11.     elif current_player == '0':
  12.         current_player = 'X'
  13.     button_x1_y1["state"] = "disabled"
  14.  
  15.  
  16. def fun2():
  17.     global current_player
  18.     button_x1_y2["text"] = current_player
  19.     check()
  20.     if current_player == '0':
  21.         current_player = 'X'
  22.     elif current_player == 'X':
  23.         current_player = '0'
  24.     button_x1_y2["state"] = "disabled"
  25.  
  26.  
  27. def fun3():
  28.     global current_player
  29.     button_x1_y3["text"] = current_player
  30.     check()
  31.     if current_player == 'X':
  32.         current_player = '0'
  33.     elif current_player == '0':
  34.         current_player = 'X'
  35.     button_x1_y3["state"] = "disabled"
  36.  
  37. def fun4():
  38.     global current_player
  39.     button_x2_y1["text"] = current_player
  40.     check()
  41.     if current_player == '0':
  42.         current_player = 'X'
  43.     elif current_player == 'X':
  44.         current_player = '0'
  45.     button_x2_y1["state"] = "disabled"
  46.  
  47. def fun5():
  48.     global current_player
  49.     button_x2_y2["text"] = current_player
  50.     check()
  51.     if current_player == 'X':
  52.         current_player = '0'
  53.     elif current_player == '0':
  54.         current_player = 'X'
  55.     button_x2_y2["state"] = "disabled"
  56.  
  57.  
  58. def fun6():
  59.     global current_player
  60.     button_x2_y3["text"] = current_player
  61.     check()
  62.     if current_player == '0':
  63.         current_player = 'X'
  64.     elif current_player == 'X':
  65.         current_player = '0'
  66.     button_x2_y3["state"] = "disabled"
  67.  
  68.  
  69. def fun7():
  70.     global current_player
  71.     button_x3_y1["text"] = current_player
  72.     check()
  73.     if current_player == 'X':
  74.         current_player = '0'
  75.     elif current_player == '0':
  76.         current_player = 'X'
  77.     button_x3_y1["state"] = "disabled"
  78.  
  79.  
  80. def fun8():
  81.     global current_player
  82.     button_x3_y2["text"] = current_player
  83.     check()
  84.     if current_player == '0':
  85.         current_player = 'X'
  86.     elif current_player == 'X':
  87.         current_player = '0'
  88.     button_x3_y2["state"] = "disabled"
  89.  
  90.  
  91. def fun9():
  92.     global current_player
  93.     button_x3_y3["text"] = current_player
  94.     check()
  95.     if current_player == 'X':
  96.         current_player = '0'
  97.     elif current_player == '0':
  98.         current_player = 'X'
  99.     button_x3_y3["state"] = "disabled"
  100.  
  101.  
  102. def check():
  103.     if button_x1_y1["text"] == button_x1_y2["text"] == button_x1_y3["text"] != '':
  104.         label1["text"] = f"Победили: {current_player}"
  105.     elif button_x1_y1["text"] == button_x2_y2["text"] == button_x3_y3["text"] != '':
  106.         label1["text"] = f"Победили: {current_player}"
  107.     elif button_x1_y1["text"] == button_x2_y1["text"] == button_x3_y1["text"] != '':
  108.         label1["text"] = f"Победили: {current_player}"
  109.     elif button_x1_y2["text"] == button_x2_y2["text"] == button_x3_y2["text"] != '':
  110.         label1["text"] = f"Победили: {current_player}"
  111.     elif button_x1_y3["text"] == button_x2_y3["text"] == button_x3_y3["text"] != '':
  112.         label1["text"] = f"Победили: {current_player}"
  113.     elif button_x1_y3["text"] == button_x2_y2["text"] == button_x3_y1["text"] != '':
  114.         label1["text"] = f"Победили: {current_player}"
  115.     elif button_x2_y1["text"] == button_x2_y2["text"] == button_x2_y3["text"] != '':
  116.         label1["text"] = f"Победили: {current_player}"
  117.     elif button_x3_y1["text"] == button_x3_y2["text"] == button_x3_y3["text"] != '':
  118.         label1["text"] = f"Победили: {current_player}"
  119.  
  120.  
  121. root = Tk()
  122. root.title("poe-pie")
  123. root.geometry("350x400")
  124.  
  125. title = Label(text="Крестики-нолики", font=('Arial', 14, "bold"))
  126. title.grid(row=1, column=1, columnspan=3, padx=75)
  127.  
  128. button_x1_y1 = Button(text="", width=5, command=fun1)
  129. button_x1_y1.grid(row=2, column=1, ipadx=6, ipady=6, pady=15)
  130.  
  131. button_x1_y2 = Button(text="", width=5, command=fun2)
  132. button_x1_y2.grid(row=2, column=2, ipadx=6, ipady=6, pady=15)
  133.  
  134. button_x1_y3 = Button(text="", width=5, command=fun3)
  135. button_x1_y3.grid(row=2, column=3, ipadx=6, ipady=6, pady=15)
  136.  
  137. button_x2_y1 = Button(text="", width=5, command=fun4)
  138. button_x2_y1.grid(row=3, column=1, ipadx=6, ipady=6, pady=15)
  139.  
  140. button_x2_y2 = Button(text="", width=5, command=fun5)
  141. button_x2_y2.grid(row=3, column=2, ipadx=6, ipady=6, pady=15)
  142.  
  143. button_x2_y3 = Button(text="", width=5, command=fun6)
  144. button_x2_y3.grid(row=3, column=3, ipadx=6, ipady=6, pady=15)
  145.  
  146. button_x3_y1 = Button(text="", width=5, command=fun7)
  147. button_x3_y1.grid(row=4, column=1, ipadx=6, ipady=6, pady=15)
  148.  
  149. button_x3_y2 = Button(text="", width=5, command=fun8)
  150. button_x3_y2.grid(row=4, column=2, ipadx=6, ipady=6, pady=15)
  151.  
  152. button_x3_y3 = Button(text="", width=5, command=fun9)
  153. button_x3_y3.grid(row=4, column=3, ipadx=6, ipady=6, pady=15)
  154.  
  155. label1 = Label(font=('Arial', 14, "bold"))
  156. label1.grid(row=5, column=1, columnspan=3, padx=75)
  157.  
  158. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement