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/.
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()
Figure 21.1: Result
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()
Figure 21.2: Result
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()
Figure 21.3: Result
Copyright © 2005-09 Python Software Foundation.
Created Thu Aug 6 21:56:06 2009 UTC