0

I have this python script running on a raspberry pi thats plugged up to a monitor so I can passively monitor my plex server. It displays the current streams, how many of them are transcode streams, and if there's a plex update available. Whenever there's an update available, the whole thing gets stuck and no longer updates with the live info.

# Import the required library
from tkinter import *
from plexapi.server import PlexServer
baseurl = 'SERVERIP'
token = 'PLEXTOKEN'
plex = PlexServer(baseurl, token)
import time

root=Tk()
# frame = Frame(master=root, width=1920, height=200)
# frame.pack()
root.overrideredirect(True)
root.wm_attributes("-topmost", True)
root.geometry("1920x200")
textv=Text(root, width=200, height=15, fg='red', bg='black', font=('helvetica',30), highlightthickness=0, borderwidth=0)
textv.place(x=0, y=0)
trans_stream=Text(root, width=20, height=15, fg='red', bg='black', font=('helvetica',30), highlightthickness=0, borderwidth=0)
trans_stream.place(x=1500, y=0)
update_avail=Text(root, width=20, height=10, fg='red', bg='black', font=('helvetica',12), highlightthickness=0, borderwidth=0)
update_avail.place(x=1500, y=120)
root.update()

def update():
    textv['text']=textv.delete("1.0", "end")
    active = []
    for session in plex.sessions():
        active.append("{}   |   {}".format(session.title, str(session.usernames)[2:-2]))
    for n in active:
        textv['text'] = textv.insert(END, n + '\n')
        
    trans_stream['text']=trans_stream.delete("1.0", "end")
    trans_count = 0
    for trans_ses in plex.transcodeSessions():
        trans_count += 1
    trans_stream['text'] = trans_stream.insert(END, 'Transcode Streams: ' + str(trans_count))
    
    update_avail['text']=update_avail.delete("1.0", "end")
    if plex.isLatest() != True:
        update_avail['text'] = trans_stream.insert(END, '\nServer not up to date')
        root.after(1000, update)
    else:
        update_avail['text'] = trans_stream.insert(END, '\nServer up to date')
        root.after(1000, update)
    

update()
root.mainloop()

I tried commenting out the root.after in the if statement that checks if theres an update availble, and adding this to the end instead.

while True:
    time.sleep(1)
    update()

But this produced the same results.

  • You're doing `textv['text'] = textv.delete("1.0", "end")`. That's not right. The `delete` and `insert` operations do their work in place and don't return anything useful. Just delete the `textv['text'] = ` in all of those lines. – Tim Roberts Nov 17 '22 at 01:14

1 Answers1

1

I'm an idiot!

I copied over from a previous section of code the part that changes the text when an update is available, and forgot to change which section of text it's changing.

Here's what I changed

from:

 update_avail['text']=update_avail.delete("1.0", "end")
    if plex.isLatest() != True:
        update_avail['text'] = trans_stream.insert(END, '\nServer not up to date')
        root.after(1000, update)
    else:
        update_avail['text'] = trans_stream.insert(END, '\nServer up to date')
        root.after(1000, update)

to:

 update_avail['text']=update_avail.delete("1.0", "end")
    if plex.isLatest() != True:
        update_avail['text'] = update_avail.insert(END, '\nServer not up to date')
        root.after(1000, update)
    else:
        update_avail['text'] = update_avail.insert(END, '\nServer up to date')
        root.after(1000, update)