Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import*
- z=0
- br=0
- s=[]
- x=[]
- o=[]
- pobjeda=False
- def main():
- global s
- a=Tk()
- z=0
- for i in range(1, 10):
- s.append(button(i, a))
- a.mainloop()
- return 0
- def button(i,a):
- t=Button(a, text=' ', height=5, width=10, command=lambda i=i: onClick(i,t,a), font=('Arial',30))
- t.grid(row=(i-1) // 3, column=(i-1) % 3)
- return 0
- def onClick(i,t,a):
- global z
- global br
- global pobjeda
- if (z):
- if int(i)not in x and int(i) not in o and not pobjeda:
- br+=1
- x.append(int(i))
- t.configure(text='X', bg="#aa00ff", fg="#220033")
- z=0
- if (1 in x and 2 in x and 3 in x or 4 in x and 5 in x and 6 in x or 7 in x and 8 in x and 9 in x or 1 in x and 4 in x and 7 in x or 2 in x and 5 in x and 8 in x or 3 in x and 6 in x and 9 in x or 1 in x and 5 in x and 9 in x or 3 in x and 5 in x and 7 in x):
- p=Label(a,text='X pobjedio',font=('Arial',30))
- p.grid(row=3,column=0)
- ni=Button(a, text='NOVA IGRA', height=5, width=10, command=lambda a=a: novaIgra(a), font=('Arial',15))
- iz=Button(a, text='IZLAZ', height=5, width=10, command=lambda a=a: izlaz(a), font=('Arial',15))
- ni.grid(row=3,column=1)
- iz.grid(row=3,column=2)
- pobjeda=True
- else:
- if int(i)not in x and int(i) not in o and not pobjeda:
- br+=1
- o.append(int(i))
- t.configure(text='O', bg="#ff9999", fg="#4d0000")
- z=1
- if (1 in o and 2 in o and 3 in o or 4 in o and 5 in o and 6 in o or 7 in o and 8 in o and 9 in o or 1 in o and 4 in o and 7 in o or 2 in o and 5 in o and 8 in o or 3 in o and 6 in o and 9 in o or 1 in o and 5 in o and 9 in o or 3 in o and 5 in o and 7 in o):
- p=Label(a,text='O pobjedio',font=('Arial',30))
- p.grid(row=3,column=0)
- ni=Button(a, text='NOVA IGRA', height=5, width=10, command=lambda a=a: novaIgra(a), font=('Arial',15))
- iz=Button(a, text='IZLAZ', height=5, width=10, command=lambda a=a: izlaz(a), font=('Arial',15))
- ni.grid(row=3,column=1)
- iz.grid(row=3,column=2)
- pobjeda=True
- if (br%9==0 and not pobjeda):
- p=Label(a,text='Nerješeno',font=('Arial',30))
- p.grid(row=3,column=0)
- ni=Button(a, text='NOVA IGRA', height=5, width=10, command=lambda a=a: novaIgra(a), font=('Arial',15))
- iz=Button(a, text='IZLAZ', height=5, width=10, command=lambda a=a: izlaz(b,a), font=('Arial',15))
- ni.grid(row=3,column=1)
- iz.grid(row=3,column=2)
- def izlaz(a):
- a.destroy()
- return 0
- def novaIgra(a):
- global x
- global o
- global pobjeda
- pobjeda=False
- x=[]
- o=[]
- a.destroy()
- main()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement