Library

TkDocs
Python interface to Tcl/Tk
tkinterbook

steps:

tk —> frame —> button/label/xxxx —-> pack

Features

title name and constraint the frame size

PROGRAM_NAME = "Footprint Editor"
root = Tk()
root.geometry('350x350')
root.title(PROGRAM_NAME)

Entry

delete and get the text.

e = Entry(master)
e.pack()
e.delete(0, END) # delete the text.
e.insert(0, "a default value") # insert the text
s = e.get() # get the text

StringVar

v = StringVar()
e = Entry(master, textvariable=v)
e.pack()
v.set("a default value")
s = v.get()

This example creates an Entry widget, and a Button that prints the current contents:

from Tkinter import *

master = Tk()

e = Entry(master)
e.pack()

e.focus_set()

def callback():
print e.get()

b = Button(master, text="get", width=10, command=callback)
b.pack()

mainloop()

e = Entry(master, width=50)
e.pack()

text = e.get()

def makeentry(parent, caption, width=None, **options):
Label(parent, text=caption).pack(side=LEFT)
entry = Entry(parent, **options)
if width:
entry.config(width=width)
entry.pack(side=LEFT)
return entry

user = makeentry(parent, "User name:", 10)
password = makeentry(parent, "Password:", 10, show="*")

content = StringVar()
entry = Entry(parent, text=caption, textvariable=content)

text = content.get()
content.set(text)

Terminology

  • cascading menus: Items are things like the “Open…” command in a File menu, but also separators between other items, and items which open up their own submenu
  • “tear off” Linux systme

Notice

  • On Mac OS X though, there is a single menubar along the top of the screen, shared by each window.

  • Handy Reference:
    fred = Button(self, fg=”red”, bg=”blue”)

After object creation, treating the option name like a dictionary index
fred[“fg”] = “red”
Use the config() method to update multiple attrs subsequent to object creation.
fred.config(fg=”red”, bg=”blue”)