python - Volume Slider using Tkinter -


i'm new coding, , attempting create juke box school project, i'm struggling create slider edit volume. i'm unsure start volume change move slider. i'm using vlc lib.

import vlc import random tkinter import * import threading    song = "" instance = vlc.instance()  def get_songs():     global song     global x     global songs     songs = filedialog.askopenfilenames()     x = 0     song = songs[x]     print(songs)     commence(song)  def pause_resume():     player.pause()  def commence(song):     global player     global x     player = instance.media_player_new()     media = instance.media_new(song)     player.set_media(media)     player.play()   def next_song():     if x >= len(songs):         print("error: can't go further")         x = 0         return     player.stop()     song = songs[x]     commence(song)        window = tk()  window.geometry("600x600") window.title('jukebox')  #pause_button = button(window, text = "next", command = next_song) #pause_button.grid(row=1, column = 2) button(window, text="start", command=get_songs).grid(column=1,row=1) button(window, text="next", command=next_song).grid(column=1,row=2) pause_button = button(window, text = "pause/resume", command = pause_resume) pause_button.grid(row=3, column = 1) menubar = menu(window) filemenu = menu(menubar, tearoff=0) filemenu.add_separator() filemenu.add_command(label="open", command=get_songs()) filemenu.add_command(label="exit", command=window.destroy) menubar.add_cascade(label="file", menu=filemenu) window.config(menu=menubar) vol = scale(window,from_ = 0,to = 1,orient = horizontal ,resolution = .1,) vol.grid(row = 1, column = 2)     window.mainloop() 

i understand i'm not using best coding practices, way can understand have written.

set command parameter when creating scale widget:

def set_volume(v):     global vol     global player     # either new volume given argument v (type: str):     # value = int(v)     # or directly scale widget (type: int)     value = vol.get()     player.audio_set_volume(value)  vol = scale(..., command=set_volume) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -