Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

tkinter not drawing shapes with negative points

This maybe a very stupid question but I am having some troubles with tkinter. I am very new to using tkinter and wanted to learn something during my free time which I don’t have much of. I have set up the canvas and everything but in a pickle when I try to dare a rectangle with negative points. I don’t kow why, it just doesn’t draw anything.

What I am trying to do is to draw a rectangle underneath one another.

I have attached the code below. It draws the rectangle which is filled with green, but when I try to draw the rectangle filled with red, nothing appears.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I really appreciate the help.

from tkinter import *

mainWindow = Tk()

drawingCanvas = Canvas(mainWindow, width=300, height=300)

drawingCanvas.pack()

drawingCanvas.create_rectangle(50, 25, 150, 75, fill="green")

drawingCanvas.create_rectangle(50, -200, 150, -100, fill="red")

mainloop()

I tried to plot the points using using a online plotter demos to check if the points are correct. It is, but whne I draw it in tkinter, the rectangle with negative points is missing/doesn’t get drawn.

>Solution :

The rectangle with negative points is not missing but is drown outside of the screen. A tkinter Canvas starts at 0/0 on the top left of the screen so negative numbers will be drawn outside the window.

Change:

drawingCanvas.create_rectangle(50, -200, 150, -100, fill="red")

To:

drawingCanvas.create_rectangle(50, 200, 150, 100, fill="red")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading