這是我的第一篇文章。我經常訪問堆棧溢出,以前我總是找到所有問題的答案,但不是今天。Tkinter無邊框標籤圖像
我嘗試在窗口中顯示圖像作爲標籤,但它不是我認爲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()
我試過選項,例如美國的「邊框寬度」,「填充」,「bordermode」和其他一些技巧,並似乎沒有任何工作,因爲我打算做的事。感謝任何幫助和想法。
謝謝,這解決了這種情況。我只能添加'highlightthickness',並不適用於ttk主題小部件。但在這種情況下切換到默認Tkinter標籤是沒有問題的。 – frankot
我偶然發現了同樣的問題。感謝您的解決方案! – zeycus