首页 > 解决方案 > 我如何在 tkinter 中创建带有背景的圆形按钮

问题描述

我有一个带有背景的 GUI,当我放置一个按钮时,borderwidth=0它会显示一个圆形按钮,但它周围有正方形。我该如何解决?

所以这是我的按钮:

exit_image = tk.PhotoImage(file="cancel.png")
button_exit = tk.Button(root,image=exit_image, borderwidth=0 ,command=quit_window)
button_exit.place(relx=0.89, rely=0.009, relwidth=0.1, relheight=0.07)

我的问题:

在此处输入图像描述

我认为问题出在我的背景图片上,但我不确定。因此,如果您对此感兴趣,这里是我如何设置背景图像的代码:

#Backround Image:
backround_image = tk.PhotoImage(file="schloss3.png")
backround_label = tk.Label(root,image = backround_image)
backround_label.place(relwidth=1, relheight=1)

标签: pythonbuttontkinter

解决方案


您需要将背景颜色设置为窗口的主颜色,看起来像黑色。

还将highlightthickness 和borderwidth 设置为0,因此图像上没有边框。

backround_label = tk.Label(root,image = backround_image,bg='black',highlightthickness=0,borderwidth=0)


推荐阅读