Creating Simple

GIS Applications

with Python

Spring 2016

Sam Giebner

Kris Johnson

Outline

Introduction - Tools & Tkinter

    Exercise #1

 

Classes - Code organization

    Exercise #2

 

Hooks - Capture user interaction

    Exercise #3

 

Modules - Connecting the dots

    Exercise #4

What is your experience with Python?

  1. A python is a type of snake
  2. Dabbled
  3. Aspiring apprentice
  4. Regular user
  5. Snake Charmer

Why create a Python GUI?

A Story about Steve...

Before

After

Some additional reasons:

  • cross-platform (               )
  • online/offline
  • GIS tasks with esri or OS
  • simple distribution
  • tap into the power of Python!

Tkinter

What is Tkinter?

  • Most commonly used GUI toolkit for Python 
  • Object-oriented layer on top of Tcl/Tk 

Tkinter Widgets

  1. Create widget instance
  2. Style widget
  3. Place widget
    # Create widget instance     
    new_button = Button(tk_instance)

    # Configure widget
    new_button['text'] = 'Click Here'
    new_button['command'] = do_something()

    # Place widget
    new_button.grid(row=0, column=2)

Classes

Classes

  • Blueprint for createing objects

Hooks

Hooks or Callbacks

Capture, tie in user interaction

def callback():
    print "clicked!"

Button(text="click me", command=callback)
def callback(number):
    print "button", number

Button(text="one",   command=lambda: callback(1)).pack()
Button(text="two",   command=lambda: callback(2)).pack()
Button(text="three", command=lambda: callback(3)).pack()

Using a single callback for multiple widgets; lamda allows for passing args to callback

Modules

What is a Module?

  • A Python object that you can bind and reference
    • Can contain:
      • Functions
      • Classes
      • Variables
      • Runnable code

What is a Package?

  • A collections of related modules

Package

__init__.py

Module.py

Subpackage

__init__.py

Module.py

Python Package Structure

Distributing Your App

Considerations

  • Execution

  • Dependencies

Made with Slides.com