Changing the background color of a tkinter window


If you want to change the window color then you can do it. But this work has to be done manually.  You Can Use win.config(bg="red").


from tkinter import *
win= Tk()
win.title("Color Chooser")
win.config(bg="#FFF8DC") #Change Background Color
win.geometry("800x350+450+86")
lbl = Label(win, text="Please Select Color For Background", bg="#FFF8DC",
foreground="red", font=("Times New Roman", 35, "bold"))
lbl.pack(pady=50)
win.mainloop()

Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.



Tkinter is widely used library for GUI application development.
Tkinter library of python which carries large numbers of widgets,
we can easily create a Graphical User Interface for our application.
Tkinter module has a package named colorchooser. colorchooser
package of the Tkinter module helps in developing the color chooser
dialog box.colorchooser has a function named askcolor() that plays
a vital role.


askcolor()

askcolor() is colorchooser package of Tkinter module. This function helps in creating a color chooser dialog box.
If You can call the function color chooser dialogue box pop up. The function returns the hexadecimal code of the color selected by the user.

Syntax: colorchooser.askcolor()

from tkinter import *
from tkinter import colorchooser
win= Tk()
win.title("Color Chooser")
win.geometry("800x350+450+86")
lbl = Label(win, text="Please Select Color For Background", bg="#FFF8DC",
foreground="red", font=("Times New Roman", 35, "bold"))
lbl.pack(pady=50)
color =colorchooser.askcolor()
colorname = color[1]
win.configure(background=colorname)
win.mainloop()


Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.


Create Color chooser Window Using Function


from tkinter import *
from tkinter import colorchooser
win= Tk()
win.title("Color Chooser")
win.geometry("800x350+450+86")
def change_your_color():
color=colorchooser.askcolor(title="Choose Color")
win.config(background=color[1])
lbl = Label(win, text="Please Choose Color For Background", bg="#FFF8DC",
         foreground="red", font=("Times New Roman", 35, "bold"))
lbl.pack(pady=50)

btn = Button(win,text="select color", font=("Times", 25, "bold italic"),
bg="#8EE5EE",command=change_your_color)
btn.pack(pady=40)

win.mainloop()

Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.


TextEditor With Colorchooser Using Function:
Or
 How to Change Background Color in Texteditor  using Colorchooser

from tkinter import *
from tkinter import colorchooser
win= Tk()
win.title("Color Chooser")
win.config(bg="#BDBDBD")
win.geometry("800x400+450+86")

def change_your_color():
color=colorchooser.askcolor(title="Choose Color")
txteditor.config(bg=color[1])

txteditor= Text(win, width=50, height=15, font=("arial", 12, "italic"))
txteditor.pack()

btn = Button(win,text="select color", font=("Times", 25, "bold italic"),
bg="#8EE5EE",command=change_your_color)
btn.pack(pady=10)

win.mainloop()


Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.



Lets Enjoy...........


Post a Comment

أحدث أقدم