Simple Labelframe Label demo

Labelframe, Label, Button – an small example that is easy to see and follow.

#Labelframe_Frame example for wikipython
#standard set up header code 2 
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.configure(background='white')
scrW = root.winfo_screenwidth()
scrH = root.winfo_screenheight()  
workwindow = str(1024) + "x" + str(768)+ "+" +str(int((scrW-1024)/2)) + "+" +str(int((scrH-768)/2))
top1 = Toplevel(root, bg="light blue")
top1.geometry(workwindow)
top1.title("Top 1 - Workwindow")
top1.attributes("-topmost", 1)  # make sure top1 is on top to start
root.update()                   # but don't leave it locked in place
top1.attributes("-topmost", 0)  # in case you use lower or lift
#exit button - note: uses grid
b3=Button(root, text="Egress", command=root.destroy)
b3.grid(row=0,column=0,ipadx=10, ipady=10, pady=5, padx=5, sticky = W+N)
#____________________________

l1bgcolor=StringVar("")

def entertest(self):
    l1.config(takefocus=1, highlightcolor="blue", highlightthickness=20)
    l1.configure(bg="yellow")

def exittest(self):
    l1.configure(bg= l1bgcolor.get(), takefocus=0, highlightthickness=0)

def flashme():
    for i in range(5):
        myBut.flash()
    if l1.cget("bg")=="linen":
        l1.configure(bg="misty rose")
    else:
        l1.configure(bg="linen")
    top1.update()

lfspacer=LabelFrame(top1, width='2.5i', height = '1.5i', bg="light blue", fg="blue2",text="This is an invisible labelframe spacer.")
lfspacer.grid(row=0, column=0)   # by setting the bg to the same as parent top1 and
lfspacer.configure(relief=FLAT)  # relief to flat this labelframe become invisible

labelframe= LabelFrame(top1, text="This is a LabelFrame", height='2i', width='3i', highlightbackground="red", highlightthickness=5)
labelframe.configure(bd=20)
labelframe.grid(row=1, column=1)
 
l1 = Label(labelframe, text="This is a label inside the LabelFrame", bd=5, relief=GROOVE, bg="gray90") #set bg if you want cget to work
l1.bind("<Enter>", entertest)
l1.bind("<Leave>", exittest)
l1.grid(row=3, column=1, padx=10, pady=10, ipadx=5, ipady=5)
l1bgcolor.set(l1.cget("background"))

myBut= Button(top1, text="Button1", bg="white", activebackground="yellow", activeforeground="blue", bd=10, command=flashme)
myBut.configure(highlightbackground='red4', highlightthickness=7, width=20)
myBut.grid(row=5, column=1, pady=15, ipady=5, ipadx=5)
top1.update()

#____________________________
root.mainloop()