[英]Tkinter's button can't change border color
Here's my Tkinter code:这是我的 Tkinter 代码:
Photoshop = Tkinter.Button(root,
text = 'Photoshop',
fg = '#37d3ff',
bg = '#001d26',
bd = 10,
highlightthickness=4,
highlightcolor="#37d3ff",
highlightbackground="#37d3ff",
borderwidth=4)
However, after I grid my Button, the color of border doesn't shows up.但是,在我对 Button 进行网格化后,边框的颜色没有显示出来。 Instead, it used default grey.相反,它使用默认的灰色。
You may place the button inside its own frame like this:您可以将按钮放在自己的框架内,如下所示:
buttonborder = Tkinter.Frame(root,
highlightbackground="#37d3ff",
highlightcolor="#37d3ff",
highlightthickness=4,
bd=0)
photoshop = Tkinter.Button(buttonborder,
text='Photoshop',
fg='#37d3ff',
bg='#001d26')
You can add your widget to a Frame and make the Frame's highlight background to be the color you want for your widget's border.您可以将您的小部件添加到框架,并使框架的高亮背景成为您想要的小部件边框颜色。 CODE Example:代码示例:
import tkinter as tk
root = tk.Tk()
buttonborder = tk.Frame(root, highlightbackground="#37d3ff",
highlightthickness=3, bd=0)
photoshop = tk.Button(buttonborder, text='Photoshop', fg='#37d3ff')
photoshop.pack()
buttonborder.pack()
root.mainloop()
You can do it with LabelFrame()
and relief
.您可以使用LabelFrame()
和relief
来做到这LabelFrame()
。 Works in windows.在窗口中工作。
from tkinter import *
App = Tk()
Border = LabelFrame(App,
bd=5, #<- Borderwidth.
bg="blue", #<- Border color.
relief=FLAT)
Border.pack(padx=10, pady=10)
Btn1 = Button(Border, #<- in Border Widget.
text="Button",
font="Arial 16 bold",
width=16,
bg="red",
fg="white",
relief=FLAT)
Btn1.pack()
App.mainloop()
There is no perfect way to do this unfortunately, But you sure can hack around and place a tkinter Frame that is just a little bigger than the actual button to set them apart by using the frame as a coloured border, Something like this.不幸的是,没有完美的方法可以做到这一点,但是您肯定可以四处走动并放置一个比实际按钮稍大的 tkinter 框架,通过使用框架作为彩色边框将它们分开,就像这样。 Should work on Win and Mac or any other OS's.. (assuming you already know how to work with tkinter root window..) `borderFrame = Frame(root, bg="red(your desired colour of choice)") borderFrame.pack(padx=21, pady=21)应该在 Win 和 Mac 或任何其他操作系统上工作..(假设你已经知道如何使用 tkinter 根窗口..)`borderFrame = Frame(root, bg="red(你想要的选择颜色)") borderFrame.pack (padx=21,pady=21)
button = Button(borderFrame, bg="blue",text="click me", relief='flat')
button.pack(padx=20, pady=20)`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.