i want same foreground colour on button which is given by command choose_me

161
January 22, 2020, at 11:30 PM
from tkinter import *
from tkinter import colorchooser

def choose_me():
    s=colorchooser.askcolor(title="select colour")
    root.config(background=s[1])
    print(s)
root =Tk()

button= Button(root,text="choose colour",command=choose_me).pack()
root.geometry("300x300")
root.mainloop()
#i need to change the foreground colour of button same as the root window ...i need some help to overcome this problem ...

i need some help #i need to change the foreground colour of button same as the root window ...i need some help to overcome this problem ...

Answer 1

Use button.config to change the foreground inside the callback function to the same color as the background of the master window chosen from the colorchooser

from tkinter import *
from tkinter import colorchooser
root = Tk()
root.geometry("300x300")
button = Button(root,text="choose colour")
button.pack()
def choose_me():
    s=colorchooser.askcolor(title="select colour")
    root.config(background=s[1])
    # assign the same color as foreground to the button
    button.config(fg=s[1])
button.config(command=choose_me)
root.mainloop()

Screenshot

Red background of root window with Red foreground of Button.

Hope this helps you.

READ ALSO
How to use OpenCV to detect a checkbox that intersects a line in a document

How to use OpenCV to detect a checkbox that intersects a line in a document

I have successfully used code to detect checkboxes in documents, following the base case similar to:

220
Python Requests Login Request doesn't work

Python Requests Login Request doesn't work

I'm trying to log into a website using the python requests library

129
How can I add a condition in 'groupby()' in pandas?

How can I add a condition in 'groupby()' in pandas?

In the dataframe described here:

144