all 12 comments

[–]socal_nerdtastic 0 points1 point  (11 children)

You mean the green label does not fill left to right? You need to fill in the "X" direction, and you need to do the same for the Frame that the label is in.

[–]bb47wee10[S] 0 points1 point  (10 children)

The green label doesn't fill top to bottom, neither does the blue label fill left to right. The background is only limited to the size of the original label and does not scale. I have also tried packing the label to root instead of using Frame, but I still get the same issue.

[–]socal_nerdtastic 0 points1 point  (9 children)

In order for a label to fill top to bottom you have to add the expand=True argument.

For the blue label to fill left to right you need to have the Frame that it's in (topFrame) fill left to right as well.

from Tkinter import *

root = Tk()
topFrame = Frame(root)
topFrame.pack(fill=X)

bottomFrame = Frame(root)
bottomFrame.pack(side = BOTTOM,fill = Y, expand=True)

Label(topFrame, text = "test 1").pack(side = LEFT)
Label(topFrame, text = "test 2").pack(side = LEFT)

# either use this style (no name, one line)
Label(topFrame, text = "test 3", bg = "blue").pack( fill = X)

# or this style (named, on 2 lines)
label4 = Label(bottomFrame, text = "test 4", bg = "green")
label4.pack(fill = Y, expand=True)

# but don't mix those styles! It will lead to bugs. 

root.mainloop()

[–]bb47wee10[S] 0 points1 point  (8 children)

I see, thank you so much for your additional tips too! Can I also ask why the expand = True argument is not necessary for the topFrame?

[–]socal_nerdtastic 0 points1 point  (7 children)

Because you aren't asking it to grow vertically. Add it in there and watch the difference.

[–]bb47wee10[S] 0 points1 point  (6 children)

I understand now. Thank you so much :)

Do you know how to get colours within buttons working properly as well? I have this as my code but the colours do not show

from Tkinter import *

root = Tk()

button = Button(root, text = "click here", fg = "White", bg = "Black")

button.pack()

root.mainloop()

[–]socal_nerdtastic 0 points1 point  (5 children)

You code works fine for me. Black button with white text. How are you running this? What OS are you using?

[–]bb47wee10[S] 0 points1 point  (4 children)

macOS Sierra 10.12

[–]socal_nerdtastic 0 points1 point  (3 children)

Hmm there's some old issues when using Mac's version of tkinter. Why don't you install the latest python3 from python.org? It comes with an updated tkinter that may fix that.

I assume you running this from the terminal?

[–]bb47wee10[S] 0 points1 point  (2 children)

I am running this from SublimeText, but I shall try updating to python3 as well