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.
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")