Software Carpentry logo

GUI Programming

April 24, 2010: We are pleased to announce that Version 4 of this course is now under development. For updates and an early peek at the content, please check out the Software Carpentry blog at http://www.software-carpentry.org/blog/.

1) Introduction

2) You Can Skip This Lecture If...

3) Dive In

import Tkinter

window = Tkinter.Tk()

question = Tkinter.Label(window, text="Are you sure you want to learn?")
ok = Tkinter.Button(window, text="OK")
cancel = Tkinter.Button(window, text="Cancel")

question.grid(row=0, column=0, columnspan=3)
ok.grid(row=1, column=1)
cancel.grid(row=1, column=2)

window.mainloop()
Dive In

Figure 21.1: Result

4) Explaining the Code

5) A More Advanced Example

import Tkinter

window = Tkinter.Tk()

titleLabel = Tkinter.Label(window, text="Calculator Ultra", font=("Helvetica", 16))

result = Tkinter.StringVar()
resultLabel = Tkinter.Label(window, textvariable=result)

equation = Tkinter.StringVar()

def evalCommand():
    result.set(eval(equation.get()))

equationEntry = Tkinter.Entry(window, textvariable=equation, font=("Futura",))
solveButton = Tkinter.Button(window, text="Enter", font=("Helvetica",), command=evalCommand)

titleLabel.grid(row=0, column=0, columnspan=3)
equationEntry.grid(row=1, column=0, columnspan=2)
solveButton.grid(row=1, column=2)

resultLabel.grid(row=3, column=0, columnspan=3)

window.mainloop()
Advanced Example

Figure 21.2: Result

6) Tkinter Mutable Types and Other Lessons

7) Event-Driven Programming

8) Model-View-Controller

9) Design Example

import Tkinter

window = Tkinter.Tk()

big = Tkinter.Button(window, text="Click me", font=("",60))
medium = Tkinter.Button(window, text="Click me")
small = Tkinter.Button(window, text="Click me", font=("",8))

big.pack()
medium.pack()
small.pack()

window.mainloop()
Design Example

Figure 21.3: Result

10) Design

11) DropBox Signup

DropBox Signup

Figure 21.4: DropBox Signup

12) LiveDrive Signup

LiveDrive Signup

Figure 21.5: LiveDrive Signup

13) Summary