0

I have created a Window using tkinter and configured the root to have a bg colour. I set bg="Black" to have the whole Window Black, but when I tested the script, the space around the Window was Black but the middle of the Window was still White.

I tried searching the internet, but I could not find anything (it may be the phrasing but I don't know a better way to phrase this). I tried different ways to phrase this question like "Why does the background colour of a Window not fill the middle?" and "Why does the bg="Black" not fill the middle in Python", but it comes up with tutorials for tkinter and picture colouring in Python.

I also tried attaching other attributes to the config but like fg="Black" but the code throws a Syntax Error stating "_tkinter.TclError: unknown option "-fg" ". I don't know what is causing this or how to fix it.

Here is the segment of the code:

def mainloop_sw():
root = tk.Tk()
root.title("Adventure")
root.geometry("250x250")
root.config(bg="Black")
app = Window(root)
app.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
root.mainloop()


if __name__ == "__main__":
    mainloop_sw()

As you can see the root is configured to have the bg="Black" but the middle section is left white.

Here is a picture for context:

Image of Window

As you can see the middle is not coloured in black, and yes, there are widgets, but all of them are coloured in black (for labels) or grey (for buttons) there are no other widgets in the program which could cover up the background. If you need a confirmation of this you can just ask for the full code.

Why is the middle bit of the Window (shown in the image above) not coloured in Black when the root is configured to have bg="Black" and how do I fix it?

  • maybe try: `root.configure(background='black')` https://stackoverflow.com/questions/2744795/background-color-for-tk-in-python – Kostas Charitidis Aug 27 '19 at 13:10
  • Set `app` background also to black. – Henry Yik Aug 27 '19 at 13:11
  • The `app` only accepts curtain attributes. `bg` or `background` is not one of them. It throws an error: "_tkinter.TclError: bad option "-bg": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side" –  Aug 27 '19 at 13:15
  • 1
    @AdamDoesCoding: `Window(` is undefind, [edit] your question and show the definition of `class/def Window(`. Also fix your indentations! – stovfl Aug 27 '19 at 13:36

1 Answers1

0

The only explanation is that Window is a Frame or some other widget with a background that is white.

The solution is to modify Window to have a background that matches the background of the root window.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • `class Window(tk.Frame):` `tk.Frame` is later defined as root. How can I change the `bg` of the `Window`? –  Aug 27 '19 at 17:34
  • @AdamDoesCoding: if it's a frame, you configure the background like you do for any other frame. – Bryan Oakley Aug 27 '19 at 17:43
  • I did some tests on that method you provided, but they did not work, so I deleted the new code and whenever I ran the script the whole Window became Black... Thanks I guess! :) –  Aug 27 '19 at 17:59