Button not working, but init is ok

This commit is contained in:
2023-12-28 17:30:43 +01:00
parent 7030dadb4a
commit 5d2e682b51
4 changed files with 38 additions and 13 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 87 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+32 -13
View File
@@ -9,22 +9,24 @@ import urllib
class RadioParadise(object):
def __init__(self):
self.title=None
self.artist=None
self.album=None
self.year=None
self.time=None
self.jpg_path=None
def rp_reload_api(self):
respons=requests.get("https://api.radioparadise.com/api/now_playing")
rp_dict=respons.json()
rp_dict=self.load_api()
self.title=rp_dict["title"]
self.artist=rp_dict["artist"]
self.album=rp_dict["album"]
self.year=rp_dict["year"]
self.time=rp_dict["time"]
self.jpg_path=rp_dict["cover"]
print(self.album)
def load_api(self):
respons=requests.get("https://api.radioparadise.com/api/now_playing")
rp_dict=respons.json()
return rp_dict
def get_list(self):
result=(self.title, self.artist, self.album, self.year, self.time)
return result
class AlbumCover(RadioParadise):
def __init__(self, path):
@@ -41,20 +43,37 @@ class AlbumCover(RadioParadise):
class RPViewer(Tk):
def __init__(self, *args, **kwargs):
def __init__(self, radioparadise, *args, **kwargs):
super().__init__(*args, **kwargs)
self.rp=radioparadise
self.title("Radio Paradise Viewer")
self.geometry("500x740")
self.resizable(False,False)
self.label=Label(self, font="Arial, 14", text="Radio Paradise now playing:")
self.label.pack()
self.button_quit=Button(self, text="Quit", command=self.quit)
self.button_refresh=Button(self, text="Refresh", command=lambda: [self.rp.load_api(),self.refresh_textbox()])
self.button_quit.pack(side=BOTTOM)
self.button_refresh.pack(side=TOP)
self.font=Font(family="Arial", size=14)
self.textbox=Text(self, height=6, width=50, font=self.font)
self.textbox.insert("1.0", self.rp.get_list())
self.textbox.pack()
def quit(self):
exit()
def refresh_textbox(self):
self.textbox.delete("1.0", "end")
self.textbox.insert("1.0", self.rp.get_list())
def main():
rp_play=RadioParadise()
rp_play.rp_reload_api()
print (rp_play.title)
print(rp_play.artist)
print (rp_play.time)
app=RPViewer()
app=RPViewer(rp_play)
app.mainloop()
if __name__=="__main__":
+6
View File
@@ -0,0 +1,6 @@
self.title=None
self.artist=None
self.album=None
self.year=None
self.time=None
self.jpg_path=None