Tkinter's button can't change border color
Solution 1
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')
Solution 2
This works for me:
import Tkinter as tk
root = tk.Tk()
Photoshop = tk.Button(root, text = 'Photoshop',
fg = '#37d3ff',
bg = '#001d26',
bd = 10,
highlightthickness=4,
highlightcolor="#37d3ff",
highlightbackground="#37d3ff",
borderwidth=4)
Photoshop.pack()
root.mainloop()
Solution 3
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()
Solution 4
You can do it with LabelFrame()
and relief
.
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()
Heatmint
Job: no job, high school student. Learn coding by self-study. Computer programming: noob on HTML, a little bit familiar with python. Python: Learned httplib and requests... Someone said if you learned python web crawler(spider), that means you just starting your python-life.(Translated by myself...It was original Chinese.) Entertainment: Writing several joking vbs and bat to make fun of my classmates.
Updated on June 14, 2022Comments
-
Heatmint almost 2 years
Here's my Tkinter code:
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. Instead, it used default grey.
-
mrid over 6 yearsthis is not a
human-readable
code -
Russell Smith over 6 yearsyou can't change the border color with tkinter.
highlightcolor
andhighlightbackground
aren't the border colors, they are colors for the highlight ring which shows when the button has focus.
-