newnewbie
newnewbie

Reputation: 1003

Python Tkinter how to color a window using grid

I am trying out Tkinter and writing a little window, using grid.

The code is as follows:

from Tkinter import *
from modules.logic import game
import options


class StartWindow:

    def __init__(self):


        data = open("myData", "w")
        data.close()
        self.master = Tk()
        self.l0 =Label (self.master, text = "W=jump", bg = "magenta", font = ("comic sans ms", 20, "bold")).grid(row=0, sticky = W)
        self.l1=Label (self.master, text = "A=left",bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row = 1, sticky = W)
        self.l2=Label(self.master, text = "D=Duck", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=2, sticky = W )
        self.l3=Label(self.master, text = "Mouse = Shoot", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=3, sticky = W)
        self.l4=Label(self.master, text = "S=Duck", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=4, sticky = W)
        self.l5=Label(self.master, text="Seed:", bg = "magenta",font = ("comic sans ms", 20, "bold")).grid(row=5, sticky = W)
        self.master.minsize(50, 50)
        self.master.weight = 2
        self.master.title("Fluffocalypse")
        self.master.iconify()    
        self.e1 = Entry(self.master)
        self.e1.grid(row=5, column=1, sticky = W)
        self.b1 =Button(self.master, text = "Start", command = self.startGameNormally).grid(row = 6, sticky = W)
        self.b2 = Button(self.master, text = "alten Spielstand laden", command =self.loadOldGame).grid(row = 7, sticky = W)
        mainloop()

It does work.

Well, for one, the text does not look like comic sans to me, but this is a minor problem.

If you try this code (please do), you see that what you get is a window with labels and buttons just where I placed them, in that magenta color I set them too.

However, the free spaces on the window remain grey. I would like to have the free spaces magenta also. Is that possible and if so how? There are a dozen explanations on how to change the color of anything that is packed, but I am not using pack() but grid, and I cannot find a solution as to how color the whole window, not just the space where my labels and buttons are.

Upvotes: 2

Views: 7952

Answers (2)

izidor
izidor

Reputation: 4144

I suppose you would like to have the background color of window to be magenta:

self.master = Tk()                                                      
self.master.configure(bg = 'magenta')

Result:

Magenta window

Upvotes: 5

Ionut Hulub
Ionut Hulub

Reputation: 6326

Just add this line to your constructor:

self.master.configure(background="magenta")

Upvotes: 2

Related Questions