[This post looks for help with Tkinter. Can someone please indicate where I should post it as I have not found an appropriate tag for it]
Hello
Average-skilled amateur programmer (Python, C, C++, Java), I decided to embark on an exploration of Tkinter as a means to implement my next GUIs.
[Environment : MacBook Pro M2, macOS 14.2.1, Python 3.12.3]
After reading a few pages of the (excellent) tutorial I was eager to experiment a number of very basic things just to check that my understanding was heading in the right direction.
No luck ! It’s been 2 days that I have been trying to jump over a first hurdle and I would need some help to try and figure out what I am doing wrong.
For my first experiment, the layout I am trying to put together is something like this :
The code I wrote :
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Tkinter (ttk) experiments – with .grid as geometry manager")
root.geometry('700x600+300+300') # width x height + screen offset
root.config(bg="skyblue")
topFrameStyle = ttk.Style()
topFrameStyle.configure('tfs.TFrame',background='green')
topFrame = ttk.Frame(root, width=680, height=190,style='tfs.TFrame')
topFrame.grid(row=0, column=0, padx=10, pady=5)
# Oops ! topFrame appearance is (default) grey not green. Checking …
print(topFrameStyle.lookup('tfs.TFrame','background')) # green
bottomFrameStyle = ttk.Style()
bottomFrameStyle.configure('bfs.TFrame', background='red')
bottomFrame = ttk.Frame(root, width=680, height=190, style='bfs.TFrame')
bottomFrame.grid(row=1, column=0, padx=10, pady=5)
# Oops ! bottomFrame appearance is (default) grey not red. Checking …
print(bottomFrameStyle.lookup('bfs.TFrame','background')) # red
#ttk.Label(topFrame, text="A label in top frame").grid(row=0, column=0, sticky = (N, W))
#ttk.Label(bottomFrame, text="A label in bottom frame").grid(row=0, column=0, sticky = (S, E))
root.mainloop()
With this code I get 2 frames on the main window ok, but they appear in grey (default, I suppose) not red and green. Why ?
Note that the Labels bit is commented out.
If I uncomment the first Label the top frame disappears alltogether and looks like it is replaced with the Label (which is not placed according to ‘sticky=(N,W)’).
And if uncomment the second Label all frames disappear and the Labels appear but at totally unexpected places.
It is plain clear that I am doing something severely wrong. Could someone give me a hand to try and put me back in the right track ?
Many thanks in advance.