简体   繁体   中英

How to change the border color of the label in tkinter?

I created a color pallete, I want to change the border color of the label, but while writing this code i am unable to change the bakcground color. Here is the code.

from tkinter import *

gui = Tk()
gui.configure(background="white")
gui.title("Color")
gui.geometry("300x600")
equation = StringVar()
equation.set('')

def bg(color):
    lbl.configure(bg=color)

def highlightborder(color):
    lbl.configure(highlightborder=color)

def addButton(Button):
    gui.configure(Add.Buttton)

    
lbl=Label(gui,text='hi')
lbl.grid(row=5,column=5)


button1 = Button(gui,bg='white',fg='red',command=lambda:highlightborder('red'),text='❑',bd=3)
button1.grid(padx=1,pady=1,row=2,column=1)

button2 = Button(gui,bg='white',fg='blue',command=lambda:highlightborder('blue'),text='❑',bd=3)
button2.grid(padx=1,pady=1,row=3,column=1)

button3 = Button(gui,bg='white',fg='green',command=lambda:highlightborder('green'),text='❑',bd=3)
button3.grid(padx=1,pady=1,row=4,column=1)

gui.mainloop()

Like mr.martineau said labels dont have a highlightborder they have insted bg of fg try this:

from tkinter import *

gui = Tk()
gui.configure(background="white")
gui.title("Color")
gui.geometry("300x600")
equation = StringVar()
equation.set('')

def bg(color):
    lbl.configure(bg=color)

def highlightborder(color):
    lbl.configure(bg=color)

def addButton(Button):
    gui.configure(Add.Buttton)

    
lbl=Label(gui,text='hi')
lbl.grid(row=5,column=5)


button1 = Button(gui,bg='white',fg='red',command=lambda:highlightborder('red'),text='❑',bd=3)
button1.grid(padx=1,pady=1,row=2,column=1)

button2 = Button(gui,bg='white',fg='blue',command=lambda:highlightborder('blue'),text='❑',bd=3)
button2.grid(padx=1,pady=1,row=3,column=1)

button3 = Button(gui,bg='white',fg='green',command=lambda:highlightborder('green'),text='❑',bd=3)
button3.grid(padx=1,pady=1,row=4,column=1)

gui.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM