Jonah Fleming
Jonah Fleming

Reputation: 1185

Why isn't my frames background showing?

I am making an app with Tkinter (2.7) that imports a frame from another file. Unfortunately though the background colour isn't showing even though I have defined it in the imported file. The text widget on the frame shows up though. I have tried taking the mainframe = … out of the class and putting it into the body of the code between the two bottom lines but to no avail.

Main file:

import Tkinter as tk
import frames

class Window(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.title("Example Code")    
        mainframe = frames.Main(start)             

start = Window()
start.mainloop()

Frame file:

import Tkinter as tk

class Main(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        self.config(background="#5fe689")
        tk.Label(text="hi").pack()

Any help is appreciated!

Upvotes: 0

Views: 56

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385900

You never put the frame in the root window. You need to call pack, place or grid on mainframe.

Upvotes: 1

Related Questions