How to draw a right angle triangle using tkinter?

谁说我不能喝 提交于 2021-02-17 05:52:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!