1

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()
  • You must be removing something else... removing just a comment line will have no impact – Helder Sepulveda Apr 25 '22 at 19:26
  • I believe this is because you are running turtle inside a tkinter window that you are making as opposed to the one turtle makes itself. Look at the answer provided by cdlane [here](https://stackoverflow.com/questions/44634947/how-to-set-a-turtle-to-a-turtle-screen/44639041#44639041). I'm pretty sure you need to have either TurtleScreen() or RawTurtle() for you canvas in order for this to draw the way you want. – Rory Apr 25 '22 at 19:38

1 Answers1

0

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.

Сергей Кох
  • 1,417
  • 12
  • 6
  • 13