Good day,
Basically what you need to have is:
- A scale.
timescale = Scale( (...)
- Setting the scale range every time a new song starts, something like this:
timescale.config(to=item['duration'])
- A loop, for which you can use
win.after(1000, timeloop)
. In the loop, you get the time of your player (time = player.get_time()
, and then pass that time to the scale, like this: timescale.set(time)
- A function that sets the player time when you move the scale:
player.set_time(timescale_var)
, with a check that the scale has actually been moved by the user, and not by the loop updating the time (therefor I put a minimum of 4000ms on the moving of the scale, otherwise it just doesn't update the player time)
- for the volume scale, it's more basic, youll see in the code below
I show you a little excerpt from my code, that does what you need. It is from a project of mine: https://github.com/floris-vos/gui-youtube-player
In that app, you'll find an implemented volume scale and time scale. Its a work in progress, currently I'm refactoring the code, and implementing some more things.
Relevant excerpts of code:
timescale = Scale(
root, from_=0, to=1000,
orient=HORIZONTAL, length=267,
showvalue=0, command=timescale_move)
#above is your timescale - embedded in root for the example
timescale.pack()
#pcak it
volumescale = Scale(
root, from_=200, to=0, orient=VERTICAL,
showvalue=0,command=change_volume)
#here the volume scale, with a maximum volume of 200%
volumescale.set(100)
#it is set by default to 100% volume
volumescale.pack()
#pack it.
def timeloop():
time = player.get_time()
#getting time from your player
timescale.set(time)
#setting the scale
win.after(1000, timeloop)
#looping
def change_volume(volume_var: int):
player.audio_set_volume(int(volume_var))
#setting volume. changing the volumescale automatically sends
#a variable with the new value
def new_song():
timescale.config(to=item['duration'])
def timescale_move(timescale_var):
if abs(int(timescale_var) - player.get_time()) > 4000:
player.set_time(int(timescale_var))
#the if check is just to be sure that the scale was moved
#a significant amount