'RadioButtons command to change the color of the text (tkinter)
I am using tkinter for this project After inputting some radio buttons, I have managed to change the color of the background of the windows itself when clicked. However, after adding another text widget, I want to change the color of that text when clicked these radio buttons. Would like to have your help in that simple command:
from tkinter import *
root = Tk()
root.title("WOOSAL")
def changeColourF(colour):
root.configure(background =colour)
choice1.configure(background =colour)
choice2.configure(background =colour)
choice3.configure(background =colour)
choice4.configure(background =colour)
v =StringVar()
v.set("L")
choice1 =Radiobutton(root, text ="red", value =1, variable =v, command =lambda: changeColourF("red"))
choice1.grid(row =0, column =0)
choice2 =Radiobutton(root, text ="blue", value =2, variable =v, command =lambda: changeColourF("blue"))
choice2.grid(row =0, column =1)
choice3 =Radiobutton(root, text ="yellow", value =3, variable =v, command =lambda: changeColourF("yellow"))
choice3.grid(row =0, column =2)
choice4 =Radiobutton(root, text ="green", value =4, variable =v, command =lambda: changeColourF("green"))
choice4.grid(row =0, column =3)
w = Label(root, text="Hello Tkinter!")
w.grid(row=1, column=0)
root.mainloop()
Solution 1:[1]
You can change text color with fg
parameter.
def changeColourF(colour):
root.configure(background=colour)
choice1.configure(background=colour)
choice2.configure(background=colour)
choice3.configure(background=colour)
choice4.configure(background=colour)
w.configure(fg=colour)
Solution 2:[2]
Write a python GUI program that contains three Radio buttons for colors “Red”, “Green”, and “Blue”. Display selected color on a label.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | F115 Varaliya Mohammed |