Home > OS >  How to change Back ground colour for Tkinter module?
How to change Back ground colour for Tkinter module?

Time:07-17

Hello I am very new with the python module Tkinter, I have written the code for a simple text editor. But I am not able to figure out how to change the background colour. Help would be welcome thx.

Code:

from tkinter import *
import tkinter as tk

# from tkinter import filedialog
# from tkinter import font


root = Tk()
root.title('Flax')
root.iconbitmap('E:\editor.ico')
root.geometry('1200x660')

# Main Frame
my_frame = Frame(root)
my_frame.pack(pady=5)

# ScrollBar
scroll = Scrollbar(my_frame)
scroll.pack(side=RIGHT, fill=Y)

# Text Box
text = Text(my_frame, width=98, height=25, font=("Helvetica", 13), selectbackground="grey", selectforeground="white", undo=True)         
        
text.pack()

scroll.config(command=text.yview)

root.mainloop()

CodePudding user response:

The parameter you need to use is bg = "blue" for example source.

Implemented into your code:

from tkinter import *
import tkinter as tk

# from tkinter import filedialog
# from tkinter import font


root = Tk()
root.title('Flax')
root.iconbitmap('E:\editor.ico')
root.geometry('1200x660')

# Main Frame
my_frame = Frame(root)
my_frame.pack(pady=5)

# ScrollBar
scroll = Scrollbar(my_frame)
scroll.pack(side=RIGHT, fill=Y)

# Text Box
text = Text(my_frame, width=98, height=25, font=("Helvetica", 13), bg="grey", fg="white", undo=True)         
        
text.pack()

scroll.config(command=text.yview)

root.mainloop()
  • Related