Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Yosemite - Apple (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 16(Creating Graphical User Interfaces)、16.7(Exercises) 5.を解いてみる。
16.7(Exercises) 5.
コード(BBEdit)
sample5.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import tkinter
def fahrenheit2celsius(fahrenheit):
return 5 / 9 * (fahrenheit - 32)
return celsius * 9 / 5 + 32
window = tkinter.Tk()
frame = tkinter.Frame(window)
frame.pack()
label = tkinter.Label(frame, text='Temperature in Fahrenheit')
label.pack()
fahrenheit = tkinter.DoubleVar()
entry = tkinter.Entry(frame, textvariable=fahrenheit)
entry.pack()
celsius = tkinter.DoubleVar()
celsius_label = tkinter.Label(frame, textvariable=celsius)
celsius_label.pack()
convert = tkinter.Button(frame, text='Convert',
command=lambda:celsius.set(
fahrenheit2celsius(fahrenheit.get())))
convert.pack()
quit = tkinter.Button(frame, text='Quit', command=window.destroy)
quit.pack()
window.mainloop()
入出力結果(Terminal, IPython)
$ ./sample5.py $
0 コメント:
コメントを投稿