4

有谁知道为什么我在以下示例中的画布上得到不同的线宽?

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()

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

4

2 回答 2

0

经过一些实验后,我想我看到了正在发生的事情——左边的一些线被画在画布外面,我认为这真的很迟钝。反正有没有画线,使它的最外面的一点在画布上?或者,有没有更简单的方法在小部件周围或画布上绘制边框?

于 2010-05-09T01:44:36.967 回答
0

When you draw a line with a width greater than 1, the extra pixels have to be drawn somewhere. As you observed in your own followup post, some of those pixels are being drawn off screen. All you need to do is adjust your original coordinates to take into account the width of the line.

于 2010-05-09T14:00:38.400 回答