Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphics Programming with Python. Many choices Python offers us several library choices:  Tkinter  WxPython  PyQt  PyGTK  Jython  And others...

Similar presentations


Presentation on theme: "Graphics Programming with Python. Many choices Python offers us several library choices:  Tkinter  WxPython  PyQt  PyGTK  Jython  And others..."— 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(' ', haha) Now, clicking this button(left) will cause your computer to laugh at you


Download ppt "Graphics Programming with Python. Many choices Python offers us several library choices:  Tkinter  WxPython  PyQt  PyGTK  Jython  And others..."

Similar presentations


Ads by Google