[英]Tkinter slider not properly controlling Pygame channel volume
在我的代碼中,我正在使用 Pygame 混音器同時播放不同的部分,並且我正在測試僅將 slider 添加到其中一個軌道。 我使用了下面的代碼,但整個 slider 的音量是恆定的,只有在達到零時才會關閉。 如何使音量逐漸下降?
# Things to note
from tkinter import *
from os import environ
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
from pygame import mixer
window = Tk()
# Pygame mixer code
mixer.init()
mixer.set_num_channels(5)
channel1 = mixer.Channel(0)
channel1Sound = mixer.Sound("bass.wav")
channel1.play(channel1Sound)
channel2 = mixer.Channel(1)
channel2Sound = mixer.Sound("drums.wav")
channel2.play(channel2Sound)
channel3 = mixer.Channel(2)
channel3Sound = mixer.Sound("other.wav")
channel3.play(channel3Sound)
channel4 = mixer.Channel(3)
channel4Sound = mixer.Sound("piano.wav")
channel4.play(channel4Sound)
channel5 = mixer.Channel(4)
channel5Sound = mixer.Sound("vocals.wav")
channel5.play(channel5Sound)
# Slider code
def volume(x):
channel5.set_volume(vocalsSlider.get())
vocalsSlider = Scale(window, from_ = 0, to=100, orient=HORIZONTAL, command=volume)
vocalsSlider.set(100)
vocalsSlider.pack()
根據關於 set_volume 的 pygame 文檔:
The value argument is between 0.0 and 1.0.
將 get() 中的值除以最大值,得到一個可以工作的浮點數。
channel5.set_volume(vocalsSlider.get()/100.0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.