Search code examples
pythontkintercanvaspython-turtle

Python Canvas not working when I remove turtle element


This program runs fine, but when I remove the commented section of the code, the lines on the canvas do not display correctly

from tkinter import *
import numpy as np
import turtle

widthx = 400
heighty = 300
ws = Tk()
ws.title('Light Sim')
ws.geometry('400x300')
ws.config(bg='white')
x = 100
y = -100

c = Canvas(bg="white", height=heighty, width=widthx,)
c.grid(row=3, column=0, stick='sw')
#screen = turtle.TurtleScreen(c)
c.create_line(y, 0, x,0, fill='blue', width=2)
c.create_line(0,y,0,x,fill='grey', width=2)

ws.mainloop()

Solution

  • The origin of coordinates in Canvas and TurtleScreen are different - the upper left corner and the center of the window. Therefore, the lines disappear - go beyond the screen.