Skip to content

Commit

Permalink
Add refresh function to song list (Right click)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManHinnn0509 committed Nov 30, 2021
1 parent f898cb4 commit 3f89619
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mp3player.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, dirPath: str) -> None:

# --- Variables
self.dirPath = dirPath if (dirPath[-1] == '\\' or dirPath[-1] == '/') else dirPath
self.songs = self.__getMP3()
self.songs = self.getMP3()

self.songIndex = 0

Expand Down Expand Up @@ -137,7 +137,7 @@ def __countPosition(self):


# For init.
def __getMP3(self):
def getMP3(self):
return [i for i in os.listdir(self.dirPath) if (i.endswith('.mp3'))]

def start(self):
Expand Down
7 changes: 7 additions & 0 deletions songlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, mp3Player: MP3Player) -> None:
listvariable=StringVar(value=self.mp3Player.songs)
)
listbox.bind('<Double-1>', self.__clickToChangeSong)
listbox.bind('<Button-3>', self.__refresh)
self.listbox = listbox

scrollbar = Scrollbar(
Expand All @@ -33,6 +34,12 @@ def __init__(self, mp3Player: MP3Player) -> None:
self.listbox.pack(fill=tk.Y, expand=True)
self.listboxFrame.pack(fill=tk.Y, side='left')

def __refresh(self, event):
self.listbox.configure(
listvariable=StringVar(value=self.mp3Player.getMP3())
)
print('hi')

def __clickToChangeSong(self, event):
selectedIndex = event.widget.curselection()[0]
self.mp3Player.songIndex = selectedIndex
Expand Down

0 comments on commit 3f89619

Please sign in to comment.