简体   繁体   English

如何使用tkinter绘制直角三角形?

[英]How to draw a right angle triangle using tkinter?

I'm trying to draw a right angle triangle with tkinter.我正在尝试用 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()

You can use polygon -function to draw a triangle.您可以使用polygon函数绘制三角形。 Just specify a list of corner-points of your triangle as argument.只需指定三角形的角点list作为参数。

points = [x1,y1, x2,y2, x3,y3]
can.create_polygon(points, fill='white')

Check out the tkinter-documentation for more info.查看tkinter 文档了解更多信息。

You should use create_polygon() to draw triangle:您应该使用create_polygon()绘制三角形:

shape2={'bounds': [20, 50, 80, 35, 80, 50], 'kind': 'tri', 'fill': True}
can.create_polygon(list(shape2.values())[0],fill='white',outline='white')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM