Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media)
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media )のChapter 8(Guis and Data: Data entry widgets)、CODE MAGNETS(p.264)を解いてみる。
CODE MAGNETS(p.264)
コード(BBEdit)
sample264.py
#!/usr/bin/env python3 #-*- coding: utf-8 import tkinter def saveData(): with open('deliveries.txt', 'a') as f: f.write('Depot:\n') f.write('{0}\n'.format(depot.get())) f.write('Description:\n') f.write('{0}\n'.format(description.get())) f.write('Address:\n') f.write('{0}\n'.format(address.get('1.0', tkinter.END))) depot.delete(0, tkinter.END) description.delete(0, tkinter.END) address.delete('1.0', tkinter.END) app = tkinter.Tk() app.title('Head-Ex Delivers') tkinter.Label(app, text='Deposit:').pack() depot = tkinter.Entry(app) depot.pack() description = tkinter.Entry(app) description.pack() address = tkinter.Text(app) address.pack() tkinter.Button(app, text='Save', command=saveData).pack() app.mainloop()
入出力結果(Terminal)
$ ./sample264.py $ cat deliveries.txt Depot: Seattle, WA Description: Books Address: 1 Main Street Anytown WA Depot: Seatle1, WA1 Description: Books1 Address: 2 Main Street Anytown1 WA1 $
0 コメント:
コメントを投稿