我在窗口中添加了图片。背景颜色为白色。图像也是白色的,但周围有一个环,将图像与窗口分隔开。如何删除图像周围的黑环?
这是窗口的屏幕截图:https://imgur.com/a/ULk4beS
window = tk.Tk()
window.configure()
ws = window.winfo_screenwidth()
hs = window.winfo_screenheight()
w = 800 # width for the Tk root
h = 600 # height for the Tk root
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
window.geometry('%dx%d+%d+%d' % (w, h, x, y))
canvas = tk.Canvas(window, bg="white", width=800, height=600)
canvas.pack()
canvas_scroll = tk.Scrollbar(canvas, command=canvas.yview)
canvas_scroll.place(relx=1, rely=0, relheight=1, anchor=tk.NE)
canvas.configure(yscrollcommand=canvas_scroll.set, scrollregion=())
photo = tk.PhotoImage(file="C:/Users/sel/Desktop/logo.png")
label = tk.Label(canvas, image=photo)
canvas.create_window(125,10, window=label, anchor=tk.NW)
l0 = tk.Label(canvas, text="강재 NESTING 최적화 프로그램", font= "calibri 32",fg="royalblue4",bg="white" )
canvas.create_window(125,70, window=l0, anchor=tk.NW)
l1 = tk.Label(canvas, text="MIN")
canvas.create_window(125,150, window=l1, anchor=tk.NW)
l2 = tk.Label(canvas, text="MAX")
canvas.create_window(260,150, window=l2, anchor=tk.NW)
l3 = tk.Label(canvas, text="Sheet 폭(SW)")
canvas.create_window(3,170, window=l3, anchor=tk.NW)
minw_var = tk.DoubleVar()
entry_minw_number = tk.Entry(canvas, textvariable=minw_var)
canvas.create_window(190,180, window=entry_minw_number)
maxw_var = tk.DoubleVar()
entry_maxw_number = tk.Entry(canvas, textvariable=maxw_var)
canvas.create_window(325,180, window=entry_maxw_number)
l4 = tk.Label(canvas, text="Sheet 높이(SH)")
canvas.create_window(3,190, window=l4, anchor=tk.NW)
minl_var = tk.DoubleVar()
entry_minl_number = tk.Entry(canvas, textvariable=minl_var)
canvas.create_window(190,200, window=entry_minl_number)
maxl_var = tk.DoubleVar()
entry_maxl_number = tk.Entry(canvas, textvariable=maxl_var)
canvas.create_window(325,200, window=entry_maxl_number)
l5 = tk.Label(canvas, text="소요 Component 개수")
canvas.create_window(3,210, window=l5, anchor=tk.NW)
rect_var = tk.IntVar()
entry_rect_number = tk.Entry(canvas, textvariable=rect_var)
canvas.create_window(260,220, window=entry_rect_number)
window.title("Rectangle Configuration")
window.mainloop()```
答案 0 :(得分:2)
似乎它是Label
的一部分,因此请使用create_image
将图像放在Canvas
上,而无需使用Label
photo = tk.PhotoImage(file="C:/Users/sel/Desktop/logo.png")
canvas.create_image(125,10, image=photo, anchor=tk.NW)
答案 1 :(得分:0)
画布具有默认边框,只需在画布上添加highlightthickness=0
即可删除
更改此
canvas = tk.Canvas(window, bg="white", width=800, height=600)
与此
canvas = tk.Canvas(window, bg="white", width=800, height=600, highlightthickness=0)