问题
I'm trying to draw a right angle triangle with tkinter. I can't figure out how to do it, I can do a rectangle and then another one but I cant get the second rectangle to be a triangle.
Here's an example of what I want to do, how far I have gotten, and my code:
What I want to do:
How far I've gotten:
My code:
from tkinter import *
root= Tk()
can = Canvas(root, width=200, height=200)
can.pack()
shape1={'bounds': [20, 20, 80, 50], 'kind': 'rect', 'fill': True}
shape2={'bounds': [80, 50, 20, 35], 'kind': 'tri', 'fill': True}
can.create_rectangle(list(shape1.values())[0],fill='black')
can.create_rectangle(list(shape2.values())[0],fill='white')
root.mainloop()
回答1:
You can use polygon
-function to draw a triangle. Just specify a list
of corner-points of your triangle as argument.
points = [x1,y1, x2,y2, x3,y3]
can.create_polygon(points, fill='white')
Check out the tkinter-documentation for more info.
回答2:
You should use create_polygon()
to draw triangle:
shape2={'bounds': [20, 50, 80, 35, 80, 50], 'kind': 'tri', 'fill': True}
can.create_polygon(list(shape2.values())[0],fill='white',outline='white')
来源:https://stackoverflow.com/questions/64210371/how-to-draw-a-right-angle-triangle-using-tkinter