# Python Programming/GUI

This lesson introduces Python graphical user interfaces using Tkinter.

## Objectives and Skills

Objectives and skills for this lesson include:
* Standard Library
** Graphical User Interfaces

## Readings

* Wikipedia: Graphical user interface
* Wikipedia: Platform-independent GUI library
* Wikipedia: Tkinter

## Multimedia

* YouTube: TkInter Tutorial
* YouTube: Python tkinter Playlist

## Examples
### The tkinter.Tk Method

The tkinter.Tk method creates a toplevel widget of Tk, which usually is the main window of an application.

### The root.title Method

The root.title method sets the window title.

### The root.maxsize Method

The maxsize method returns the maximum size available for the window.

### The root.geometry Method

The geometry method sets the size and offset in pixels for the window.

### The tkinter.scrolledtext Object

The tkinter.scrolledtext object implements a basic text widget with a vertical scroll bar.

### The pack Method

The pack method packs widgets into the available window space.

### The scrolledtext.insert Method

The scrolledtext.insert method inserts text into the scrolled tex widget.

### tkinter scrolledtext Example

The following example demonstrates using tkinter to display a scrolling text window.

### tkinter canvas Example

The following example demonstrates using tkinter to draw canvas shapes.

## Activities
### Tutorials

* Complete one or more of the following tutorials:
** TutorialsPoint
*** GUI Programming
** ZetCode
*** Introduction to Tkinter

### Practice

* Modify one or more of the Python Programming/Files#Practice activities so that the input is passed from the command line and the output is displayed in a Tkinter scrolledtext window.
* Modify one or more of the Python Programming/Internet Data#Practice activities so that the input is passed from the command line and the output is displayed in a Tkinter scrolledtext window.
* Modify one or more of the Python Programming/Databases#Practice activities so that the input is passed from the command line and the output is displayed in a Tkinter scrolledtext window.

## Lesson Summary
### GUI Concepts

* A graphical user interface (GUI) is type of user interface that allows users to interact with electronic devices through graphical icons and visual indicators such as secondary notation, instead of text-based user interfaces, typed command labels or text navigation.
* Designing the visual composition and temporal behavior of a GUI is an important part of software application programming in the area of human–computer interaction.
* The goal of human-computer interaction is to enhance the efficiency and ease of use for the underlying logical design of a stored program, a design discipline named usability.
* Typically, users interact with information by manipulating visual widgets that allow for interactions appropriate to the kind of data they hold.
* Large widgets, such as windows, usually provide a frame or container for the main presentation content such as a web page, email message or drawing. Smaller ones usually act as a user-input tool.
* The most common combination of widget elements in GUIs is the windows, icons, menus, pointer (WIMP) paradigm.
* A Platform Independent Graphical User Interface package is a software library that a programmer uses to produce GUI code for multiple computer platforms.
* Most platform-independent Graphical User Interface packages slow the execution of the resulting code, and programmers are largely limited to the feature set provided by the package library.
* Web browsers offer a convenient alternative to GUI packages for many applications. Web browsers utilize HTML as a presentation layer for applications hosted on a central server, and web browsers are available for most platforms.
* Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit, and is Python's de facto standard GUI.
* There are several popular GUI library alternatives available, such as wxPython, PyQt (PySide), Pygame, Pyglet, and PyGTK.
* A Tkinter top-level window is a window that exists independently on the screen. It will be decorated with the standard frame and controls for the desktop manager. It can be moved around the desktop, and can usually be resized.
* Widget is the generic term for any of the building blocks that make up an application in a graphical user interface. Examples of widgets: buttons, radiobuttons, text fields, frames, and text labels.

### Python GUI

* The tkinter.Tk method creates a toplevel widget of Tk, which usually is the main window of an application.
* The root.title method sets the window title.
* The maxsize method returns the maximum size available for the window.
* The geometry method sets the size and offset in pixels for the window.
* The tkinter.scrolledtext object implements a basic text widget with a vertical scroll bar.
* The pack method packs widgets into the available window space.
* The scrolledtext.insert method inserts text into the scrolled tex widget.

## Key Terms
### button

    Any graphical control element that provides the user a simple way to trigger an event.

### checkbutton

    A GUI widget that permits the user to make a binary choice, i.e. a choice between one of two possible mutually exclusive options.

### entry

    A graphical control element intended to enable the user to input text information to be used by the program.

### frame

    A type of box within which a collection of graphical control elements can be grouped as a way to show relationships visually, either because the items are functionally related (such as a radio button), or because they apply to related objects.

### label

    A graphical control element which displays text on a form. It is usually a static control; having no interactivity.

### radiobutton

    A graphical control element that allows the user to choose only one of a predefined set of options.

### scrollbar

    A widget in which continuous text, pictures, or other content can be scrolled in a predetermined direction (up, down, left, or right) on a computer display, window, or viewport so that all of the content can be viewed, even if only a fraction of the content can be seen on a device's screen at one time.

### window

    A graphical control element which consists of a visual area containing some of the graphical user interface of the program it belongs to and is framed by window decoration.

## Review Questions

* A graphical user interface (GUI) is _____. A graphical user interface (GUI) is type of user interface that allows users to interact with electronic devices through graphical icons and visual indicators such as secondary notation, instead of text-based user interfaces, typed command labels or text navigation.
* Designing the visual composition and temporal behavior of a GUI is _____. Designing the visual composition and temporal behavior of a GUI is an important part of software application programming in the area of human–computer interaction.
* The goal of human-computer interaction is to _____. The goal of human-computer interaction is to enhance the efficiency and ease of use for the underlying logical design of a stored program, a design discipline named usability.
* Typically, users interact with information by _____. Typically, users interact with information by manipulating visual widgets that allow for interactions appropriate to the kind of data they hold.
* Large widgets, such as _____, usually _____. Smaller ones usually _____. Large widgets, such as windows, usually provide a frame or container for the main presentation content such as a web page, email message or drawing. Smaller ones usually act as a user-input tool.
* The most common combination of widget elements in GUIs is the _____ paradigm. The most common combination of widget elements in GUIs is the windows, icons, menus, pointer (WIMP) paradigm.
* A Platform Independent Graphical User Interface package is _____. A Platform Independent Graphical User Interface package is a software library that a programmer uses to produce GUI code for multiple computer platforms.
* Most platform-independent Graphical User Interface packages _____. Most platform-independent Graphical User Interface packages slow the execution of the resulting code, and programmers are largely limited to the feature set provided by the package library.
* Web browsers offer _____. Web browsers offer a convenient alternative to GUI packages for many applications. Web browsers utilize HTML as a presentation layer for applications hosted on a central server, and web browsers are available for most platforms.
* Tkinter is _____. Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit, and is Python's de facto standard GUI.
* There are several popular GUI library alternatives available, such as _____, _____, _____, _____, and _____. There are several popular GUI library alternatives available, such as wxPython, PyQt (PySide), Pygame, Pyglet, and PyGTK.
* A Tkinter top-level window is _____. A Tkinter top-level window is a window that exists independently on the screen. It will be decorated with the standard frame and controls for the desktop manager. It can be moved around the desktop, and can usually be resized.
* Widget is _____. Widget is the generic term for any of the building blocks that make up an application in a graphical user interface. Examples of widgets: buttons, radiobuttons, text fields, frames, and text labels.
* The tkinter.Tk method _____. The tkinter.Tk method creates a toplevel widget of Tk, which usually is the main window of an application.
* The root.title method _____. The root.title method sets the window title.
* The maxsize method _____. The maxsize method returns the maximum size available for the window.
* The geometry method _____. The geometry method sets the size and offset in pixels for the window.
* The tkinter.scrolledtext object _____. The tkinter.scrolledtext object implements a basic text widget with a vertical scroll bar.
* The pack method _____. The pack method packs widgets into the available window space.
* The scrolledtext.insert method _____. The scrolledtext.insert method inserts text into the scrolled tex widget.

## Assessments

* Flashcards: Quizlet: GUI Programming
* Flashcards: Quizlet: Tkinter
* Quiz: Quizlet: GUI Programming
* Quiz: Quizlet: Tkinter

## See Also

* Python.org: GUI Programming