0

I need to combine python turtle and tkinter for tic tac toe game, I looked at some sites and tried, but it didn't worked as I imagine, so I need help. Code:

from turtle import *
from circle import Tac
from cross import Tic
from tkinter import *

screen = Screen()
screen.title("Tic Tac Toe")
screen.setup(width=300, height=500)
tim = Turtle()
board = "board.gif"
screen.addshape(board)
img_turtle = Turtle()
img_turtle.shape(board)
screen.listen()
tim.penup()
tim.seth(0)

Code I want to add:

button1 = Button(text="button", command=tic.one)
button1.place(x=-70, y=42)
Marko
  • 123
  • 1
  • 10
  • This is making it more complicated than it needs to be. You could have all your code in `tkinter`, and not use `turtle` at all. If you use `tkinter`'s `Canvas` widget, you can easily draw a tic tac toe board, and get click events from the user for placing game pieces. – Sylvester Kruin Jan 07 '22 at 16:14

1 Answers1

1

Python turtle is designed to operate either standalone or embedded in a larger tkinter program. You're trying to use the standalone interface in an embedded situation. Below is my rework of what I would have expected your code to look like. Since you didn't provide a runnable example, this is an incomplete sketch:

from tkinter import *
from turtle import RawTurtle, TurtleScreen
from circle import Tac
from cross import Tic

BOARD = "board.gif"

root = Tk()
root.title("Tic Tac Toe")

canvas = Canvas(root, width=300, height=500)
canvas.pack(side=LEFT)

screen = TurtleScreen(canvas)
screen.addshape(BOARD)

tim = RawTurtle(screen)
tim.penup()

img_turtle = RawTurtle(screen)
img_turtle.shape(BOARD)

button = Button(root, text="button", command=tic.one)
button.pack()

screen.mainloop()
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
cdlane
  • 40,441
  • 5
  • 32
  • 81