gpt4 book ai didi

python - tkinter 多边形

转载 作者:太空宇宙 更新时间:2023-11-04 00:30:14 28 4
gpt4 key购买 nike

我对 tkinter 比较陌生,我正在制作一个只使用正方形的游戏。我正在抄写的书只显示三角形。这是代码:

# The tkinter launcher (Already complete)
from tkinter import *
HEIGHT = 500
WIDTH = 800
window = Tk()
window.title ('VOID')
c = Canvas (window, width=WIDTH, height=HEIGHT, bg='black')
c.pack()
# Block maker (Issue)
ship_id = c.create_polygon (5, 5, 5, 25, 30, 15, fill='red')

我没有收到任何错误,它只是一串数字,(5, 5, 5, 25, 30, 15) 我没有收到,因为我试图做一个正方形。

最佳答案

摘要Canvas.create_polygon definition :

As displayed, a polygon has two parts: its outline and its interior. Its geometry is specified as a series of vertices [(x0, y0), (x1, y1), … (xn, yn)] (...)

id = C.create_polygon(x0, y0, x1, y1, ..., option, ...)

所以你需要按照这个指定的顺序传递正方形的坐标。例如:

myCanvas.create_polygon(5, 5, 5, 10, 10, 10, 10, 5)

可以理解为

myCanvas.create_polygon(5,5, 5,10, 10,10, 10,5)

将创建一个正方形,其顶点为 (5, 5)(5, 10)(10, 10)(10, 5)

关于python - tkinter 多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46082381/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com