Python Forum
[Tkinter] AttributeError: 'tuple' object has no attribute 'replace'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] AttributeError: 'tuple' object has no attribute 'replace'
#1
from   tkinter  import   *
import    pygame
from   tkinter    import   filedialog

root  =   Tk()
root.title('bynet  mp3 player')

root.geometry("500x300")

#   Initialze   Pygame  Mixer
pygame.mixer.init()



#Add   Song   Function
def   add_song():
	       song   =   filedialog.askopenfilenames(initialdir='audio/',   title="Choose  A  Song",   filetypes=(("mp3  Files",  "*.mp3"),   ))
	       
           #strip    out   the  directory   info    and  .mp3     extension   from   the   song   name  
	       song   =    song.replace("serverlow@serverlow:~/music/audio",   "")
	       song   =    song.replace(".mp3",    "")

           #   Add  song   to   listbox
	       song_box. insert(END,   song)



#   Create  Playlist    Box
song_box   =   Listbox(root,  bg="black",  fg="green",  width=60)
song_box.pack(pady=20)

#   Define  Player   Control   Buttons   Images
back_btn_img   =   PhotoImage(file='image/back50.png')
forward_btn_img   =      PhotoImage(file='image/forward50.png')
play_btn_img   =      PhotoImage(file='image/play50.png')  
pause_btn_img   =      PhotoImage(file='image/pause50.png')
stop_btn_img   =      PhotoImage(file='image/stop50.png')

#  Create  Player   Control   Frames
controls_frame   =    Frame(root)
controls_frame.pack()

#   Create   Player   Control   Buttos   
back_button   =    Button(controls_frame,  image=back_btn_img,   borderwidth=0)
forward_button     =  Button(controls_frame,  image=forward_btn_img,  borderwidth=0)
play_button   =    Button(controls_frame,  image=play_btn_img,    borderwidth=0)
pause_button   =    Button(controls_frame,  image=pause_btn_img,    borderwidth=0)
stop_button   =       Button(controls_frame,  image=stop_btn_img,    borderwidth=0)

back_button.grid(row=0,   column=0 ,   padx=10)
forward_button.grid(row=0,   column=1,     padx=10)
play_button.grid(row=0,   column=2,    padx=10)
pause_button.grid(row=0,   column=3,    padx=10)
stop_button.grid(row=0,   column=4,   padx=10)

#   Create   Menu
my_menu   =   Menu(root)
root.config(menu=my_menu)

#   Add  Add   Song    Menu
add_song_menu   =    Menu(my_menu)
my_menu.add_cascade(label="Add   Song",  menu=add_song_menu)
add_song_menu.add_command(label="Add  One  Song  To   Playlist",   command=add_song)

root.mainloop()
----------------------------------------------------------------
Error:
serverlow@serverlow:~/music$ python3 music.py pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.8/tkinter/__init__.py", line 1883, in __call__ return self.func(*args) File "music.py", line 20, in add_song song = song.replace("serverlow@serverlow:~/music/audio", "") AttributeError: 'tuple' object has no attribute 'replace
Reply


Messages In This Thread
AttributeError: 'tuple' object has no attribute 'replace' - by linuxhacker - Jul-30-2020, 11:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'NoneType' object has no attribute 'get' zunebuggy 8 1,539 Oct-13-2023, 06:39 PM
Last Post: zunebuggy
  tkinter AttributeError: 'GUI' object has no attribute pfdjhfuys 3 1,671 May-18-2023, 03:30 PM
Last Post: pfdjhfuys
  [Kivy] Windows 10: AttributeError: 'WM_PenProvider' object has no attribute 'hwnd' mikepy 1 2,411 Feb-20-2023, 09:26 PM
Last Post: deanhystad
  [Tkinter] Can't update label in new tk window, object has no attribute tompranks 3 3,670 Aug-30-2022, 08:44 AM
Last Post: tompranks
  [PyGUI] [Solved]Replace attribute for Floats Extra 5 4,659 Jun-10-2022, 05:44 PM
Last Post: deanhystad
  AttributeError: 'NoneType' object has no attribute 'get' George87 5 15,723 Dec-23-2021, 04:47 AM
Last Post: George87
  [PyQt] AttributeError: 'NoneType' object has no attribute 'text' speedev 9 11,604 Sep-25-2021, 06:14 PM
Last Post: Axel_Erfurt
  [Tkinter] AttributeError: '' object has no attribute 'tk' Maryan 2 14,857 Oct-29-2020, 11:57 PM
Last Post: Maryan
  [Kivy] AttributeError: 'NoneType' object has no attribute 'bind' faszination_92 2 6,349 Apr-12-2020, 07:01 PM
Last Post: Larz60+
  AttributeError: '_tkinter.tkapp' object has no attribute 'place_forget' edphilpot 5 9,295 Dec-20-2019, 09:52 PM
Last Post: joe_momma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020