Python/Tkinter root window background configuration
24,786
This works (Check how parent root is referenced):
Edit: I edited the code and figure to make clear where colors are set:
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.parent = master
self.initUI()
def initUI(self):
self.outputBox = Text(self.parent, bg='yellow', height= 10, fg='green', relief=SUNKEN, yscrollcommand='TRUE')
self.outputBox.pack(fill='both', expand=True)
self.button1 = Button(self.parent, text='button1', width=20, bg ='blue', fg='green', activebackground='black', activeforeground='green')
self.button1.pack(side=RIGHT, padx=5, pady=5)
self.button2 = Button(self.parent, text='button2', width=25, bg='white', fg='green', activebackground='black', activeforeground='green')
self.button2.pack(side=LEFT, padx=5, pady=5)
def main():
root = Tk()
app = Application(root)
app.parent.geometry('300x200+100+100')
app.parent.configure(background = 'red')
app.mainloop()
main()
Author by
user1435947
Updated on July 09, 2022Comments
-
user1435947 almost 2 years
I'm trying to create a root window with a black background to blend with my button backgrounds.
I have the following:
class Application(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.initUI() ... def initUI(self): self.outputBox = Text(bg='black', fg='green', relief=SUNKEN, yscrollcommand='TRUE') self.outputBox.pack(fill='both', expand=True) self.button1 = Button(self, text='button1', width=40, bg ='black', fg='green', activebackground='black', activeforeground='green') self.button1.pack(side=RIGHT, padx=5, pady=5) self.button2 = Button(self, text='button2', width=20, bg='black', fg='green', activebackground='black', activeforeground='green') self.button2.pack(side=LEFT, padx=5, pady=5) ... def main(): root = Tk() root.geometry('1100x350+500+300') root.configure(background = 'black') app = Application(root) root.mainloop()
But
root.configure(background = 'black')
isn't changing the root window's background color... any suggestions?