如何使用tkinter绘制直角三角形? [英] How to draw a right angle triangle using tkinter?
本文介绍了如何使用tkinter绘制直角三角形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用 tkinter 绘制一个直角三角形.我不知道怎么做,我可以先做一个矩形,然后再做另一个,但我不能让第二个矩形变成三角形.
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:
我想做什么:
我已经走了多远:
我的代码:
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()
推荐答案
您可以使用 polygon
-function 来绘制三角形.只需指定三角形角点的 list
作为参数.
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')
查看 tkinter 文档了解更多信息信息.
Check out the tkinter-documentation for more info.
这篇关于如何使用tkinter绘制直角三角形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文