python - Tkinter 标签图像无边框

标签 python tkinter label

这是我的第一篇文章。我经常访问 stack overflow,我以前总能找到所有问题的答案,但今天不行。

我尝试在窗口中将图像显示为标签,但我认为 Tkinter 不会这样显示它们。换句话说。我有几张小图片,它们应该并排放置,没有任何间隙。但除了我所有的努力之外,Tkinter 总是在两个相邻元素之间放置小边框或间隙(可能是 1-2 像素)。

from tkinter import *
from tkinter import ttk

class MainWindow():

def __init__(self, mainWidget):

    self.status_bar_text = StringVar()
    self.status_bar_text.set('')

    self.image_to_place = PhotoImage(file='my_image.png')

    self.main_frame = ttk.Frame(mainWidget, width=768, height=480, padding=(0, 0, 0, 0))
    self.main_frame.place(x=0, y=0)

    self.status_bar = ttk.Label(mainWidget, width=768, border=1, anchor=W, relief=SUNKEN, textvariable=self.status_bar_text)
    self.status_bar.place(x=0, y=480)

    self.main_gui()

def main_gui(self):
    i = 0
    plate_cords = [[0, 0], [24, 0], [48, 0], [72, 0], [96, 0], [120, 0]]

    for plate in plate_cords:
        self.wall_label = ttk.Label(self.main_frame, image=self.image_to_place)
        self.wall_label.place(x=plate_cords[i][0], y=plate_cords[i][1])
        i += 1
    del i


def main():
    global root
    root = Tk()
    root.title('Title')
    root.geometry('768x500+250+100')
    root.rowconfigure(0, weight=1)
    root.columnconfigure(0, weight=1)

    window = MainWindow(root)
    window

    root.mainloop()

if __name__ == '__main__':
    main()

我尝试了诸如“borderwidth”、“padding”、“bordermode”之类的选项和其他一些技巧,但似乎没有任何效果符合我的预期。感谢您的帮助和想法。

最佳答案

有两个属性需要设置为 0(零):borderwidthhighlightthicknessborderwidth(与 relief 一起)定义了小部件的实际边框。 highlightthickness 还定义了某种边框——它是一个矩形环,当小部件获得焦点时可见。

关于python - Tkinter 标签图像无边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31360480/

相关文章:

python - 如何提高以下 python 代码的性能

python - 在 Python 中处理惰性 JSON - 'Expecting property name'

python - 属性错误 : 'AxesSubplot' object has no attribute 'Circle' Embedding matplotlib in tkinter

python - Tkinter 绑定(bind)鼠标双击

javascript - 只需单击标签即可双击

python - Twisted 聊天客户端只在发送消息后直接接收消息?

python - 如何一次更改 tkinter GUI 中所有内容的颜色

javascript - 如何使用 d3.js 为圆环图中的数据创建标签

javascript - jquery 切换标签

python - Anaconda Python virtualdev 在适用于 Linux 的 Windows 子系统 (Ubuntu 14.04) 上找不到 libpython3.5m.so.1.0