# GUI3.py
# Written by Todd Wareham for CS 2500
"""
Executes basic Python GUI with examples of various widgets nested frames,
each of which has a different layout-type.

This version implements widget resizing under window size change.
"""


import sys
from Tkinter import *

## Root window setup

root = Tk()
root.title(sys.argv[0])

## Global GUI data-variables

iv1 = IntVar()
iv2 = IntVar()
dv  = DoubleVar()
sv1 = StringVar()
sv1.set("Left!")
sv2 = StringVar()

## Callback functions

def reset():
    sv2.set("Top2! : " + sv1.get())
    return

## GUI frames / widgets

## Top frame / widgets

tf = Frame(root)

Label(tf, text="Top1!").grid(row=1, column=1)
reset()
Label(tf, textvariable=sv2).grid(row=3, column=1)
Scale(tf, label="Top3!", variable=dv, from_=0.0, to=4.0, 
      tickinterval=1.0, resolution=0.5, showvalue=YES, 
      orient='horizontal').grid(row=2, column=2)

tf.pack(expand=YES, fill=BOTH, side=TOP)

## Bottom widgets

iv1.set(1)
Checkbutton(root, variable=iv1, text="Bottom!").pack(expand=YES, fill=BOTH, side=BOTTOM)
Button(root, text="Reset Top2", command=reset).pack(expand=YES, fill=BOTH, side=BOTTOM)

## Left widgets

Entry(root, textvariable=sv1).pack(expand=YES, fill=BOTH, side=LEFT)

## Right frame / widgets

rf = Frame(root)

iv2.set(2)
Radiobutton(rf, variable=iv2,  value=1, text="Right1").pack(expand=YES, fill=BOTH, side=TOP)
Radiobutton(rf, variable=iv2,  value=2, text="Right2").pack(expand=YES, fill=BOTH, side=TOP)
Radiobutton(rf, variable=iv2,  value=3, text="Right3").pack(expand=YES, fill=BOTH, side=TOP)

rf.pack(expand=YES, fill=BOTH, side=RIGHT)

## "Center" widget

Button(root, text="Exit", command=sys.exit).pack()

## GUI execution

root.mainloop()
