2

Visual Programming in Python

You can make very nice visual interfaces using the tkinter toolkit provided with Python. It gives you tools for creating windows, buttons, radio buttons, check boxes, entry fields, list boxes, combo boxes and a number of other useful visual widgets.

To use the tkinter library, you must tell your program to import those tools:

import tkinter as tk
from tkinter import *

Then you set up the window like this:

# set up the window
root = tk.Tk()              # get the window

You create a Hello button with:

# create Hello button
slogan = Button(root,
                   text="Hello",
                   command=disp_slogan)

Then you put in the layout:

slogan.pack()

The command argument refers to the function ...

Get Python Programming with Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.