Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tic Tac Toe problem
#1
I have been doing a work on Tic tac toes but I need help with the positioning I have set that when I press a button I draw a circle or an X but the problem is that it can draw where it wants but I need it to make it dead center of the square.

import tkinter
canvas=tkinter.Canvas(width=700, height=700)
canvas.pack()

def board():
    canvas.create_line(50,150,350,150)
    canvas.create_line(150,50,150,350)
    canvas.create_line(250,50,250,350)
    canvas.create_line(50,250,350,250)
    canvas.create_rectangle(50,50,350,350)

    
def kruh(sur):
    x=sur.x
    y=sur.y
    canvas.create_oval(x-30,y-30,x+30,y+30, fill='blue')

canvas.bind('<Button-1>', kruh)

def stvorec(sur):
    x=sur.x
    y=sur.y
    canvas.create_rectangle(x-30,y-30,x+30,y+30,fill='red')

canvas.bind('<Button-3>', stvorec)

Attached Files

Thumbnail(s)
       
Reply


Messages In This Thread
Tic Tac Toe problem - by JustDarkWTF - Jan-14-2022, 06:02 PM
RE: Tic Tac Toe problem - by Yoriz - Jan-14-2022, 06:12 PM
RE: Tic Tac Toe problem - by BashBedlam - Jan-17-2022, 02:00 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020