PhungSize
PhungSize

Reputation: 21

Python Turtle Objects in conjuction with tkinter is it possible?

I'm having an issue when I run my main.py, it shows two screens. I know it's because I'm calling an object, just not sure if it's possible to use objects and have it show up on the tkinter window.

main.py

import tkinter as tk
from turtle import TurtleScreen
from createDotTest import Dot
top = tk.Tk()

canvas = tk.Canvas(top, width=600, height=600)
canvas.pack()

screen = TurtleScreen(canvas) 
screen.tracer(0)

list_of_points = []
list_of_lines = []

for x in range(100):
    dot = Dot()
    list_of_points.append(dot)

screen.mainloop()

createDotTest.py

from turtle import Turtle
import random

class Dot(Turtle):
    def __init__(self):
        super().__init__()
        x_pos = random.randint(-280, 280)
        y_pos = random.randint(-280, 280)
        self.shapesize(.2,.2)
        self.penup()
        self.shape('circle')
        self.goto(x_pos, y_pos)
        self.stamp()

I tried also replacing Turtle as TurtleRaw in the createDotTest.py but I get

raise TurtleGraphicsError("bad canvas argument %s" % canvas)
turtle.TurtleGraphicsError: bad canvas argument None

Upvotes: 2

Views: 108

Answers (1)

mudit dagar
mudit dagar

Reputation: 21

This question looks similar to Combine tkinter and turtle

I am not sure but this may help you

Upvotes: 1

Related Questions