0

在 Python 3.2.5 和 tkinter 中,我不断在包含图像(两侧没有白色边框)的中间标签(三个堆叠标签)的顶部和底部获得 1 或 2 个“额外”的类似边框的像素。无论我如何缩小窗口或指定无边框宽度,我都会在标签的顶部和底部之外得到几个像素。

这是代码....

        root.withdraw()

        LoginErrorMsg = tk.Toplevel()

        LoginErrorMsg.title('ERROR! Unauthorized Login Attempt')

        # pick .gif file
        # load the file and covert it to a tkinter image object
        imageFile = "ErrorLogin.gif"
        image1 = tk.PhotoImage(file=imageFile)

        #set size of Error Message Window
        width = 348
        height = 480

        #get size of the whole screen
        xmax = LoginErrorMsg.winfo_screenwidth()
        ymax = LoginErrorMsg.winfo_screenheight()

        #calculate centered window coordinates and position it
        x0 = xmax/2 - width/2
        y0 = ymax/2 - height/2
        LoginErrorMsg.geometry("%dx%d+%d+%d" % (width, height, x0, y0))

        # make the root window the size of the image
        #root.geometry("%dx%d+%d+%d" % (325, 475, x+100, y+100))

        # remove tk icon
        LoginErrorMsg.wm_iconbitmap('Ethicsicon.ico')

        #if user closes Error Message Window, clean up memory
        LoginErrorMsg.protocol("WM_DELETE_WINDOW", handler)

        # root has no image argument, so use a label as a panel
        panel1 = tk.Label(LoginErrorMsg, text="\nYou have exceeded three (3) login attempts.", background = "white", borderwidth = 0)
        #panel1.configure(background = 'white')
        panel1.pack(side='top', fill='both', expand='yes')
        panel2 = tk.Label(LoginErrorMsg, image=image1, background = "white", borderwidth = 0)
        panel2.pack(side='top', fill='both', expand='yes')
        panel3 = tk.Label(LoginErrorMsg, text="", borderwidth = 0)
        panel3.pack(side='top', fill= 'both', expand='yes')

        # save the panel's image from 'garbage collection'
        panel1.image = image1

        # put a button on the image panel
        button2 = tk.Button(panel3, text = '  OK  ', command = LeaveSystemCallback)
        button2.pack(side='top')

        LoginErrorMsg.update()
4

1 回答 1

0

尝试将highlightthickness每个标签的属性更改为零。

于 2013-11-10T12:57:42.927 回答