Basic_frame_label_button.py

The title says it all. Examples can be found below of Frame, Label, and Button.  To be honest, if you go through all the examples in the series the button and label widgets are used just about everywhere.


# Standard TEST AREA: Frame, Label, Button
# standard set up header code 2 - creates root + a toplevel window
# and puts a button on the root in the upper left corner to destroy the root
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)
#____________________________
#
# Create a frame in the toplevel widow
frame = Frame(top1, relief=RIDGE, borderwidth=2)
frame.pack(fill=BOTH,expand=1)
# then pack a simple label and button in the frame
label = Label(frame, text="Hello, World")
label.pack(fill=X, expand=1)
# don't even need a callback function - just use a command
# but this does not kill the root, just the toplevel
button = Button (frame,text="Exit", command=top1.destroy, bg='red')
button.pack(side=BOTTOM, pady=20)
#____________________________
root.mainloop()