Jan-14-2022, 06:02 PM
(This post was last modified: Jan-14-2022, 06:03 PM by JustDarkWTF.)
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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) |