这是一些示例代码:
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
root['background'] = 'black'
# this image here is just a placeholder. For the real application I will be using an image that is not a solid color.
image = tk.PhotoImage(width=1,height=1)
image.put(data='red', to=(0,0))
image = image.zoom(32, 32)
label = ttk.Label(root, image=image)
label.grid()
label = tk.Label(root, image=image)
label.grid(row=1,column=1)
root.mainloop()
此代码会将图像放入Label
小部件中,但对我而言,问题是图像周围有边框,如此屏幕截图所示:
您如何使图像成为标签的唯一可见部分(即您只看到没有边框/填充的图像)?