def CurrentSongInfo(self): def OnPlayListClick(event): newsongtitle = PlayList.get(PlayList.curselection()) for i in range(0, int(length)): try: if (songlist[i]['title'] == newsongtitle): newsongindex = i break except KeyError: if (songlist[i]['artist'] == newsongtitle): newsongindex = i break rpi.playid(songlist[newsongindex]['id']) rpi.update() def ftime(time): time = int(time) return str(int(time / 60)) + ':' + '%.2d' % int(time % 60) self.currentsong = StringVar(self) rpi.update() cs = rpi.currentsong() ss = rpi.status() try: artist = cs['artist'] except KeyError: artist = '**' try: album = cs['album'] except KeyError: album = '**' try: title = cs['title'] except KeyError: title = '**' #track = cs['track'] try: num = str(int(ss['song']) + 1) except KeyError: num = '' length = ss['playlistlength'] try: cur_time = ftime(ss['time'].split(':')[0]) except KeyError: cur_time = "0:00" # total time try: total_time = ftime(cs['time']) except KeyError: total_time = "0:00" self.currentsong.set(artist + ' - ' + title + '\n' + album + '\n' + num + '/' + length + '\n\n' + cur_time + '/' + total_time) lblframe = LabelFrame(self, text="Now Playing", width=600, height=100) lblframe.grid(row=1, column=0, columnspan=7, pady=40) #lblframe.grid(row=0, column=1) lblframe.grid_propagate(0) lbl = Label(lblframe, textvariable=self.currentsong, font=('Tahoma', (9))) lbl.grid(row=1, column=0) lbl.grid_propagate(0) PlayList = Listbox(self, width=80) PlayList.grid(row=3, column=1, columnspan=5, padx=20) songlist = rpi.playlistid() for i in range(0, int(length)): try: PlayList.insert(i, songlist[i]['title']) except KeyError: PlayList.insert(i, songlist[i]['artist']) if (len(cs) != 0): if (cs['id'] == songlist[i]['id']): PlayList.itemconfig(i, background='blue', foreground='white') PlayList.bind('<<ListboxSelect>>', OnPlayListClick)