gpt4 book ai didi

python - 不同的线宽与 canvas.create_line?

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:34 24 4
gpt4 key购买 nike

有谁知道为什么我在下面的示例中 Canvas 上的线宽不同?

from Tkinter import *
bigBoxSize = 150

class cFrame(Frame):
def __init__(self, master, cwidth=450, cheight=450):
Frame.__init__(self, master, relief=RAISED, height=550, width=600, bg = "grey")
self.canvasWidth = cwidth
self.canvasHeight = cheight
self.canvas = Canvas(self, bg="white", width=cwidth, height=cheight, border =0)
self.drawGridLines()
self.canvas.pack(side=TOP, pady=20, padx=20)

def drawGridLines(self, linewidth = 10):
self.canvas.create_line(0, 0, self.canvasWidth, 0, width= linewidth )
self.canvas.create_line(0, 0, 0, self.canvasHeight, width= linewidth )

self.canvas.create_line(0, self.canvasHeight, self.canvasWidth + 2, self.canvasHeight, width= linewidth )
self.canvas.create_line(self.canvasWidth, self.canvasHeight, self.canvasWidth, 1, width= linewidth )

self.canvas.create_line(0, bigBoxSize, self.canvasWidth, bigBoxSize, width= linewidth )
self.canvas.create_line(0, bigBoxSize * 2, self.canvasWidth, bigBoxSize * 2, width= linewidth)


root = Tk()
C = cFrame(root)
C.pack()
root.mainloop()

真的让我很沮丧,因为我不知道发生了什么。如果有人可以帮助我,那就太好了。谢谢!

最佳答案

当你绘制一条宽度大于 1 的线时,额外的像素必须绘制在某处。正如您在自己的后续帖子中所观察到的,其中一些像素正在从屏幕上消失。您需要做的就是调整原始坐标以考虑线条的宽度。

关于python - 不同的线宽与 canvas.create_line?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2796306/

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