文档介绍:Python Short Python Short CourseCourseLecture 6: Tk GraphicsLecture 6: Tk GraphicsRichard P. MullerMaterials and Process Simulation CenterJune 22, 2000? 2000 Richard P. Muller2Tk Tk OverviewOverview?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? 2000 Richard P. Muller3Hello, WorldHello, Worldfrom Tkinter import *w=Label(text="Hello, World!")()()?Label() defines a label to be displayed–text= specifies a parameter to be passed in?pack() resizes the window to the proper size?mainloop() enters the event loop, and the program idles until a button is pushed, a menu is pulled, etc. It has to idle until the program is killed, since we didn't define any events.? 2000 Richard P. Muller4Events (Hello, Goodbye)Events (Hello, Goodbye)from Tkinter import *w=Label(text="Hello, World).pack()b=Button(text="Goodbye",command='exit').pack()mainloop()?Button label defined by text parameter?Button defines a callback function, something to run when it is pushed.?Now mainloop() has an event to catch, so when we push the button, mainloop() executes the mand.? 2000 Richard P. Muller5Creating a Molecular EditorCreating a Molecular EditorMenu barLabelText area (for geometry input)Text entryRadio buttonsCheckbox? 2000 Richard P. Muller6Molecular Editor OverviewMolecular Editor Overview?We're going to whiz through this fairly quickly–Example is online for those who want more–Just a survey of some different widgets–How you can build a professional looking interface? 2000 Richard P. Muller7Widgets Creation RoutineWidgets Creation Routine def makeWidgets(self): frame = Frame(self) (frame) (frame) (frame) (frame)