Python Short Course Lecture 6: TK Graphics
Python Short Course Lecture 6: TK Graphics
Lecture 6: Tk Graphics
Richard P. Muller
Materials and Process Simulation Center
June 22, 2000
Tk Overview
• Set of widgets designed by John K. Ousterhout, 1987
• Based on Apple Hypercard idea of putting together
graphics program
• Tk == Tool Kit
• Mean to be driven by Tcl (Toolkit Control Language)
– Many people find Tcl limited
– Can also drive Tk with Perl, Python
• Tkinter is the Python Tk Interface
– Very easy to use
Menu bar
Label
Text entry
Radio buttons
Checkbox
Menu bar
Label
Text entry
Radio buttons
Checkbox
def confirm_quit():
d = Dialog(None, title="Goodbye?",
text="Really Leave?", default=0,
bitmap=DIALOG_ICON, strings=("Yes","No"))
if d.num ==0:sys.exit()
return
l = Label(text="Hello, World!").pack()
b = Button(text="Goodbye",
command=confirm_quit).pack()
mainloop()
root = Tk()
– Set up the dialog box
filename=LoadFileDialog(root)
– Run it. Optionally you can give it a default directory and file
filter, as shown here:
filename.go("~/gallery","*.xyz")
print filename