Reputation: 29
I am trying to change the background of the window of my gui. Can someone explain why this don't work.
I am using python version 3.6.3
from tkinter import *
class Window(Frame):
#Initialize the Window
def __init__(self, master=None, bg = "#a6a6a6"):
# Parameters that you want to send through the window
Frame.__init__(self, master)
self.master = master
self.bg = bg
root = Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop()
Upvotes: 0
Views: 15096
Reputation: 2189
self.master.configure(background='black')
Should do the job.
You make a variable called self.bg
which stores the background color, however dont set it. Replace self.bg
with the above code and change black to reflect the desired color.
e.g. self.master.configure(background=bg)
The resulting code would be
from tkinter import *
class Window(Frame):
def __init__(self, master=None, bg = "#a6a6a6"):
Frame.__init__(self, master)
self.master = master
self.master.configure(background='black')
root = Tk()
root.geometry("400x300")
app = Window(root)
root.mainloop()
Upvotes: 2