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

Copy of Creating Simple GIS Applications with Python

By Kris Johnson

Copy of Creating Simple GIS Applications with Python

Using a stand alone graphic user interface (GUI) allows for the development of powerful apps that can utilize a wide variety of GIS software and can be easily shared cross-platform. This workshop will teach you the basics of creating stand alone GUI’s for your Python scripts using the Tkinter native Python package. In this workshop, you will learn the necessary Python concepts for creating Tkinter GUI’s, including classes and modules, as well as how to utilize the many widgets available in the Tkinter package. We will also create several simple GIS tools with the Tkinter GUI and discuss tool sharing best practices. You’ll leave with the skills and knowledge necessary for creating your own stand alone Python app!

  • 480