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)、SHARPEN YOUR PENCIL(p.333)を解いてみる。
SHARPEN YOUR PENCIL(p.333)
コード(BBEdit)
sample333.py
#!/usr/bin/env python2.7
#-*- coding: utf-8 -*-
# python3.xではtkinter, python2.xではTkinter
from Tkinter import *
import pygame.mixer
def trackToggle():
if track_playing.get() == 1:
track.play()
else:
track.stop()
def shutdown():
track.stop()
app.destroy()
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')
track_playing = IntVar()
track_button = Checkbutton(app, variable=track_playing, command=trackToggle,
text='Start/Stop')
track_button.pack()
app.protocol('WM_DELETE_WINDOW', shutdown)
app.mainloop()
入出力結果(Terminal)
$ ./sample333.py $
0 コメント:
コメントを投稿