1 / 12

Graphics Programming with Python

Graphics Programming with Python. Many choices. Python offers us several library choices: Tkinter WxPython PyQt PyGTK Jython And others. Tkinter. Tkinter is the 'standard' library for programming Python GUI's because it is: Accessible (lightweight and easy-to-use)

laszlo
Download Presentation

Graphics Programming with Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphics Programming with Python

  2. Many choices • Python offers us several library choices: • Tkinter • WxPython • PyQt • PyGTK • Jython • And others...

  3. Tkinter • Tkinter is the 'standard' library for programming Python GUI's because it is: • Accessible (lightweight and easy-to-use) • Portable (runs cross-platform) • Available (standard module in the Python library) • Well-documented • Python's interface to tk, GUI library for Tcl

  4. Code Example • from Tkinter import Label • widget = Label(None, text='Hello World!') • widget.pack() • widget.mainloop()

  5. Hello World! • Create new label, placed in highest level window • Default arrangement (top side) • mainloop() shows window and starts event handling

  6. Packing • pack() method invokes geometry manager which controls layout • 'widgets' are arranged within containers (window, frame, etc.) • Containers within containers → hierarchical GUI display • Grid geometry as alternative

  7. Code Example • from Tkinter import * • Label(text='Hello World!').pack(expand=YES, fill=BOTH) • mainloop()

  8. Resizing • Windows can be resized by default • Expand causes all available space within a container to be allocated to this widget • As consequence, centers widget if alone • Fill makes the widget physically stretch to fill this space (BOTH means both horizontally(X) and vertically (Y))

  9. Code Example • from Tkinter import * • widget = Label() • widget['text'] = 'Hello World!' • widget.pack(side=TOP) • mainloop()

  10. Code Example • from Tkinter import * • root = tk() • widget = Label(root) • widget.config(text='Hello World!') • widget.pack(side=TOP, expand=YES) • root.title('MyWindow') • root.mainloop()

  11. Code Example • import sys • from Tkinter import * • widget = Button(None, text='Goodbye!', command=sys.exit) • widget.pack(side=RIGHT) • widget.mainloop()

  12. Binding Events • Def haha(): • print 'Hahahahaha!' • widget = Button(None, text='HAHA') • widget.bind('<Button-1>', haha) • Now, clicking this button(left) will cause your computer to laugh at you

More Related