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 10(Graphical Interface Elements: Selecting the right tool)、CODE MAGNETS(p.315)を解いてみる。
CODE MAGNETS(p.315)
コード(BBEdit)
sample315.py
#!/usr/bin/env python2.7 #-*- coding: utf-8 -*- # python3.xではtkinter, python2.xではTkinter from Tkinter import * import pygame.mixer def trackStart(): track.play(loops = -1) def trackStop(): track.stop() sound_file = '50459_M_RED_Nephlimizer.wav' mixer = pygame.mixer mixer.init() track = mixer.Sound(sound_file) app = Tk() app.title('Head First Mix') app.geometry('250x250+200+100') start_button = Button(app, command=trackStart, text='Start') start_button.pack(side=LEFT) stop_button = Button(app, command=trackStop, text='Stop') stop_button.pack(side=RIGHT) app.mainloop()
入出力結果(Terminal)
$ ./sample315.py $
0 コメント:
コメントを投稿