2 Standard GUI Test Setups

Updated 12/19/17  – Over the course of testing the commands, methods, options and attributes in order to vet what we say about them a simple standard GUI starting point has developed.  Eventually past articles and code will be reexamined in light of what we have learned.  In the meantime, the following code has proved to be utilitarian enough to perhaps be useful to a beginner as a starting place in testing stuff on your own.  If you have a better idea, please share it.

Hands on testing is the very best way to learn Python and tkinter. This is one of two we use frequently

#TEST AREA forcommands/methods/options/attributes
#standard set up header code 
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.configure(background='white')
scrW = root.winfo_screenwidth()
scrH = root.winfo_screenheight() 
workwindow = str(scrW-200) + "x" + str(scrH-150)+"+90"+"+70"
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(top1, text="end it all", command=root.destroy)
b3.grid(row=0,column=0,ipadx=10, ipady=10, pady=5, padx=5, sticky = W+N)
#____________________________
'''
 Your testing stuff here. We settled on using .grid so probably
 better if you usually start with .grid(row=1, column=1)
 Do NOT try to mix geometry managers! Nothing good will happen.
'''
#____________________________
root.mainloop())

When you run this, it should look something like this:

…and this version moves the exit button to the corner of the root screen and limits the top1 work area to 1024×768 which, once upon a time, was THE top end, high resolution, can’t-believe-how-big laptop display. My how times change. Any way, for a small ap or controller script this covers 99.6% of all working laoptops.


#TEST AREA forcommands/methods/options/attributes
#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)
#____________________________
'''
Your testing stuff here. We settled on using .grid so probably
better if you usually start with .grid(row=1, column=1)
Do NOT try to mix geometry managers! Nothing good will happen.
'''
#____________________________
root.mainloop()

and will look like this: (note the Egress button in top left hand corner.