combobox ta müzik çalar programını biraz geliştirdim. Şarkı seçilince çalmaya başlıyor.
-----
import pygame
from tkinter import *
import tkinter.ttk as ttk
import glob
import os
from PIL import ImageTk, Image
pencere = Tk()
pencere.tk_setPalette("light green")
pencere.geometry("800x300+250+120")
play = ImageTk.PhotoImage(file="play.png")
stop = ImageTk.PhotoImage(file="stop.png")
pause = ImageTk.PhotoImage(file="pause.png")
rewind = ImageTk.PhotoImage(file="rewind.png")
devam = ImageTk.PhotoImage(file="devam.png")
pygame.mixer.init()
liste= (glob.glob("*.mp3"))
if len(liste)<1:
showinfo("UYARI !","Programın bulunduğu dizine birkaç şarkı ekleyin !")
pencere.destroy()
label1 = Label(text="Müzik seç : ")
label1.place(x=10, y=20)
combo = ttk.Combobox()
combo["values"] = liste
combo.set(liste[0])
combo.place(x=80, y=20)
label2 = Label(text="Ses : ")
label2.place(x=250, y=20)
def çal1():
pygame.mixer.music.stop()
def çal2():
pygame.mixer.music.unpause()
def çal3():
pygame.mixer.music.pause()
def çal15():
pygame.mixer.music.rewind()
def çal5(event=None):
pygame.mixer.music.load(combo.get())
pygame.mixer.music.play()
combo.bind('<<ComboboxSelected>>', çal5)
frame1 = Frame(pencere)
frame1.pack(side = BOTTOM)
buton1=Button(frame1)
buton1.config(text="baştan çal",image=rewind,compound="top",command=çal15)
buton1.pack(side=RIGHT)
buton2=Button(frame1)
buton2.config(text="duraklat",image=pause,compound="top",command=çal3)
buton2.pack(side=RIGHT)
buton3=Button(frame1)
buton3.config(text="devam",image=devam,compound="top",command=çal2)
buton3.pack(side=RIGHT)
buton4=Button(frame1)
buton4.config(text="dur",image=stop,compound="top",command=çal1)
buton4.pack(side=RIGHT)
buton5=Button(frame1)
buton5.config(text="çal",image=play,compound="top",command=çal5)
buton5.pack(side=RIGHT)
def ses(_=None):
pygame.mixer.music.set_volume(vol.get()/100)
vol = Scale(
pencere,
from_ = 0,
to = 100,
orient = HORIZONTAL ,
resolution = 1,
tickinterval=10,
length=300,
command=ses
)
vol.set(100)
vol.pack()
mainloop()