2

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
PhungSize
  • 21
  • 2

1 Answers1

1

This question looks similar to Combine tkinter and turtle

I am not sure but this may help you

  • 1
    Thanks! I took a look at that. The issue is, I have two separate python files. Maybe I could try combining them, but I wanted to keep main.py it's own thing. – PhungSize Feb 23 '22 at 02:17
  • Could you append the solution from within the link to this answer. The content in the links does change and we dont trust even other SO links here. Thanks! – Simas Joneliunas Feb 23 '22 at 02:22