Mar-19-2022, 05:06 PM
(This post was last modified: Mar-19-2022, 06:10 PM by Yoriz.
Edit Reason: Added error tags
)
Dear deanhystad,
I tried to create a form in tkinter because, as you mentioned, the player shouldn't have to install some extra packages.
(I'm planning to create an exe to give to someone.)
The form should let the user choose which tracks should be randomly played in the background (while playing the game).
What I try to achieve is:
First, the user is told to select the tracks he likes.
These tracks are appended to the list listl.
Then the playlist should be generated by choosing randomly from listl.
Doing so, I try to generate a playlist, which is different each time it is generated.
When a playlist ends, the next playlist is played and so on...
I try to let the user randomly hear only tracks he likes.
I've got a specific question:
In function "insert_into_playlist" is the following error:
I tried to create a form in tkinter because, as you mentioned, the player shouldn't have to install some extra packages.
(I'm planning to create an exe to give to someone.)
The form should let the user choose which tracks should be randomly played in the background (while playing the game).
What I try to achieve is:
First, the user is told to select the tracks he likes.
These tracks are appended to the list listl.
Then the playlist should be generated by choosing randomly from listl.
Doing so, I try to generate a playlist, which is different each time it is generated.
When a playlist ends, the next playlist is played and so on...
I try to let the user randomly hear only tracks he likes.
I've got a specific question:
In function "insert_into_playlist" is the following error:
Error:D:\Daten\tkintermenu\main.py:56: DeprecationWarning: The *random* parameter to shuffle() has been deprecated
since Python 3.9 and will be removed in a subsequent version.
playlist.append(random.shuffle(listl, 1))
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "D:\Daten\tkintermenu\main.py", line 82, in isChecked
insert_into_playlist(listl, playlist)
File "D:\Daten\tkintermenu\main.py", line 56, in insert_into_playlist
playlist.append(random.shuffle(listl, 1))
File "C:\Users\...\AppData\Local\Programs\Python\Python310\lib\random.py", line 403, in shuffle
j = floor(random() * (i + 1))
TypeError: 'int' object is not callable
Would you please have a look on my attempt and could you tell me what I'm doing wrong (when I try to shuffle the tracks from list listl = filling the playlist)?import tkinter, pygame, random from tkinter import * master = Tk() master.geometry('500x400') pygame.init() a = "Adeline Yeo (HP) - Kite Fly High" b = "Nul Tiel Records - Fireflies" c = "cryptic scenery - Endzeit Endlos" d = "cryptic scenery - Helix Spire" e = "cryptic scenery - Minsk Metro" f = "cryptic scenery - Stazione Termini" g = "cryptic scenery - The Future was Japanese" h = "Ketsa - Holding The Line" i = "Maarten Schellekens - Salt Lake Swerve" j = "Strobotone - Dance Track" pygame.mixer.init() pygame.mixer.music.set_volume(0.7) def start_playlist(playList): # Loading first audio file into our player pygame.mixer.music.load(playList[0]) playList.pop(0) # Playing our music pygame.mixer.music.play() if len(playList) > 1: pygame.mixer.music.queue(playList[0]) playList.pop(0) # setting up an end event which host an event # after the end of every song pygame.mixer.music.set_endevent(pygame.USEREVENT) running = True while running: # checking if any event has been # hosted at time of playing for event in pygame.event.get(): # A event will be hosted # after the end of every song if event.type == pygame.USEREVENT: if len(playList) > 0: pygame.mixer.music.queue(playList[0]) playList.pop(0) if not pygame.mixer.music.get_busy(): running = False break def insert_into_listl(listl, track): # Adding songs file in our listl listl.append(track) def insert_into_playlist(listl, playlist): # Adding songs file in our playlist for i in range(len(listl)): playlist.append(random.shuffle(listl, 1)) start_playlist(playlist) def isChecked(): listl = [] playlist = [] if cb1.get() is True: insert_into_listl(listl, a) if cb2.get() is True: insert_into_listl(listl, b) if cb3.get() is True: insert_into_listl(listl, c) if cb4.get() is True: insert_into_listl(listl, d) if cb5.get() is True: insert_into_listl(listl, e) if cb6.get() is True: insert_into_listl(listl, f) if cb7.get() is True: insert_into_listl(listl, g) if cb8.get() is True: insert_into_listl(listl, h) if cb9.get() is True: insert_into_listl(listl, i) if cb10.get() is True: insert_into_listl(listl, j) insert_into_playlist(listl, playlist) def play1(): pygame.mixer.music.load(a + ".mp3") pygame.mixer.music.play() def play2(): pygame.mixer.music.load(b + ".mp3") pygame.mixer.music.play() def play3(): pygame.mixer.music.load(c + ".mp3") pygame.mixer.music.play() def play4(): pygame.mixer.music.load(d + ".mp3") pygame.mixer.music.play() def play5(): pygame.mixer.music.load(e + ".mp3") pygame.mixer.music.play() def play6(): pygame.mixer.music.load(f + ".mp3") pygame.mixer.music.play() def play7(): pygame.mixer.music.load(g + ".mp3") pygame.mixer.music.play() def play8(): pygame.mixer.music.load(h + ".mp3") pygame.mixer.music.play() def play9(): pygame.mixer.music.load(i + ".mp3") pygame.mixer.music.play() def play10(): pygame.mixer.music.load(j + ".mp3") pygame.mixer.music.play() l = Label(master, text="Welche tracks sollen zufällig gespielt werden (mit playlist)?", font=('arial', 12, 'bold', 'italic')) l.place(x=0, y=0) button1 = tkinter.Button(master, text="reinhören", command=play1) button1.place(x=0, y=25) button2 = tkinter.Button(master, text="reinhören", command=play2) button2.place(x=0, y=50) button3 = tkinter.Button(master, text="reinhören", command=play3) button3.place(x=0, y=75) button4 = tkinter.Button(master, text="reinhören", command=play4) button4.place(x=0, y=100) button5 = tkinter.Button(master, text="reinhören", command=play5) button5.place(x=0, y=125) button6 = tkinter.Button(master, text="reinhören", command=play6) button6.place(x=0, y=150) button7 = tkinter.Button(master, text="reinhören", command=play7) button7.place(x=0, y=175) button8 = tkinter.Button(master, text="reinhören", command=play8) button8.place(x=0, y=200) button9 = tkinter.Button(master, text="reinhören", command=play9) button9.place(x=0, y=225) button10 = tkinter.Button(master, text="reinhören", command=play10) button10.place(x=0, y=250) cb1=BooleanVar() cb2=BooleanVar() cb3=BooleanVar() cb4=BooleanVar() cb5=BooleanVar() cb6=BooleanVar() cb7=BooleanVar() cb8=BooleanVar() cb9=BooleanVar() cb10=BooleanVar() Checkbutton1 = Checkbutton(master, text=a, variable=cb1) Checkbutton1.place(x=75, y=25) Checkbutton2 = Checkbutton(master, text=b, variable=cb2) Checkbutton2.place(x=75, y=50) Checkbutton3 = Checkbutton(master, text=c, variable=cb3) Checkbutton3.place(x=75, y=75) Checkbutton4 = Checkbutton(master, text=d, variable=cb4) Checkbutton4.place(x=75, y=100) Checkbutton5 = Checkbutton(master, text=e, variable=cb5) Checkbutton5.place(x=75, y=125) Checkbutton6 = Checkbutton(master, text=f, variable=cb6) Checkbutton6.place(x=75, y=150) Checkbutton7 = Checkbutton(master, text=g, variable=cb7) Checkbutton7.place(x=75, y=175) Checkbutton8 = Checkbutton(master, text=h, variable=cb8) Checkbutton8.place(x=75, y=200) Checkbutton9 = Checkbutton(master, text=i, variable=cb9) Checkbutton9.place(x=75, y=225) Checkbutton10 = Checkbutton(master, text=j, variable=cb10) Checkbutton10.place(x=75, y=250) button11 = tkinter.Button(master, text="ausgewählte tracks zu playlist hinzufügen", command=isChecked) button11.place(x=75, y=275) mainloop()Have a nice weekend and many thanks for your effort!