Why does the background color of my Frame not change during the execution of my application in Tkinter, even with the setting of the bg parameter?

Asked

Viewed 39 times

0

    from tkinter import *

class Teste(object):
    def __init__(self):
        mestre = Tk()
        mestre.title("Aplicação de teste")
        mestre.geometry("400x400")
        mestre.resizable(False, False)

        #Frames
        self.frame1 = Frame(mestre, bg = "red")
        self.frame1.pack()
        self.frame2 = Frame(mestre, bg = "blue")
        self.frame2.pack()

        mestre.mainloop()
Teste()

Why, even defining the arguments "red" and "blue" respectively to the background parameter of self.frame1 and self.frame2, does the execution of the program return me a screen with the gray background color? There wasn’t supposed to be a screen split in half, each half with a color?

Thank you.

1 answer

1

is that when you create a Frame, by default the Width and its Height is 0, so they are red and blue.

height=

Default is 0. (height/height)

width=

Default value is 0. (width/Width)

So the correct way to create your Frames is as follows:

#Frames
self.frame1 = Frame(mestre, bg = "red", height=200, width=400)
self.frame2 = Frame(mestre, bg = "blue", height=200, width=400)

has a very good site that helps when looking for references to the Tkinter called Effbot. http://effbot.org/tkinterbook

  • Dear, thank you very much for the answer! Worst of all is that I studied a lot using this same site that you indicated and still had not connected me in this standard of width and height.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.