how do I make a triangle with a provided x and y position and a width and height

Viewed 84

I have a some code to create a triangle

from tkinter import *

tk = Tk()
tk.geometry("600x600")

canvas = Canvas(tk)

def triangle(x, y, w, h):
    points = [x, y, (x+h)-(w/2), (x+h)+(w/2)]
    
    canvas.create_polygon(points)

    canvas.pack(fill=BOTH, expand=True)

triangle(300, 300, 50, 50)

tk.mainloop()

when I run the code, nothing appears and I don't know why. Is there something wrong with my math to calculate the points?

0 Answers
Related