Marko
Marko

Reputation: 133

Combining python turtle and tkinter`

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)

Upvotes: 0

Views: 640

Answers (1)

cdlane
cdlane

Reputation: 41872

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()

Upvotes: 1

Related Questions