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)、LONG EXERCISE(p.342)を解いてみる。
LONG EXERCISE(p.342)
コード(BBEdit)
sample342.py
#!/usr/bin/env python2.7 #-*- coding: utf-8 -*- # python3.xではtkinter, python2.xではTkinter # python3.xでpygame.mixerモジュールを上手くインストールできてないので2.7を使用 from Tkinter import * import pygame.mixer def trackToggle(): if track_playing.get() == 1: track.play() else: track.stop() def shutdown(): track.stop() app.destroy() def changeVolume(a): track.set_volume(volume.get()) sound_file = '50459_M_RED_Nephlimizer.wav' mixer = pygame.mixer mixer.init() track = mixer.Sound(sound_file) app = Tk() app.title('Head First Mix') track_playing = IntVar() track_button = Checkbutton(app, variable=track_playing, command=trackToggle, text='50459_M_RED_Nephlimizer.wav') track_button.pack(side=LEFT) volume = DoubleVar() volume_scale = Scale(app, variable = volume, from_ = 0.0, to = 1.0, resolution = 0.1, command = changeVolume, label = 'Volume', orient = HORIZONTAL) volume_scale.pack(side=RIGHT) app.protocol('WM_DELETE_WINDOW', shutdown) app.mainloop()
入出力結果(Terminal)
$ ./sample342.py $
0 コメント:
コメントを投稿