0

Hi i have this simple code which creates a tkinter window, resizes it and draws a line. Why this line is being drawn almost in the center when it should start at the top left corner? (See the photo attached)

import tkinter
# window size
window_size = 20 * 20
root = tkinter.Tk()
root.geometry('{}x{}'.format(window_size * 2, window_size))
root.resizable(width=False, height=False)
canvas = tkinter.Canvas(root)
canvas.pack()
canvas.create_line(0, 0, 100, 100, fill='red', width=10)
root.mainloop()

enter image description here

1 Answer 1

1

You need that canvas would fill the window: (canvas.pack(fill='both'))

The complete code for canvas to take whole window space:

canvas.pack(side="top", fill="both", expand=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.