fra*_*kot 3 python tkinter labels
这是我的第一篇文章.我经常访问堆栈溢出,我以前总是找到所有问题的答案,但今天不是.
我尝试在窗口中将图像显示为标签,但这并不是我认为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()
Run Code Online (Sandbox Code Playgroud)
我试过像'borderwidth','padding','bordermode'和其他一些技巧这样的选项,似乎没什么可行的,因为我打算这样做.感谢您的帮助和想法.
有两个属性需要设置为0(零):borderwidth和highlightthickness.borderwidth(以及relief)定义窗口小部件的实际边框.highlightthickness还定义了各种边框 - 它是一个矩形环,当窗口小部件具有焦点时可见.
| 归档时间: |
|
| 查看次数: |
5145 次 |
| 最近记录: |