【问题标题】:how can i create round buttons in tkinter with an backround如何在具有背景的 tkinter 中创建圆形按钮
【发布时间】:2021-02-14 01:43:34
【问题描述】:

我有一个带有背景的 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)

【问题讨论】:

  • 即使图像是透明的,Button 小部件的背景也不透明。

标签: python button tkinter


【解决方案1】:

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

同样将highlightthickness和borderwidth设置为0,这样图片上就没有边框了。

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

【讨论】:

    【解决方案2】:

    最好的方法是将图像的背景颜色编辑为 tkinter 表单的背景。

    【讨论】:

    • 是的,我也试过这个,但是那个命令是什么。 bg="backround_image" 不起作用 (^.^)/
    • @razerGr33n bg 期望字符串中的颜色名称?
    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 2011-03-13
    • 1970-01-01
    • 2021-08-05
    • 2014-11-21
    相关资源
    最近更新 更多