I am struggling to get a simple GUI to work with python (2.7) on Raspberry Pi (Buster).
I have tried Tkinter and PySimpleGUI but both of these effectively use while loops and I already have such a loop in my program, which is working without issue. Both Tkinter and PySimpleGUI block the main loop.
Attempts to run Tkinter and PySimpleGUI in a thread do not seem to work, various elements are not thread compliant and hang with various error messages. In any case it appears that once in a thread you can't interact with the GUI widgets unless you create complicated queues and they are not thread safe.
All I am trying to do is write out the print 'Alert Door statement (last line of the while loop) into a text field (something pretty / colourful) and then have an alarm sound (GPIO) and a button which clears the alarm and text field.
Any thoughts apreciated, it appears the available Pi GUIs are just not suitable. Be gentle, I am a newbie.
def vp_start_gui():
#'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
redalert_support.init(root, top)
root.mainloop()
w = None
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
font13 = "-family {Segoe UI} -size 22"
font14 = "-family {Segoe UI} -size 21"
top.geometry("480x300+267+205")
top.minsize(120, 1)
top.maxsize(1028, 749)
top.resizable(1, 1)
top.title("SecuriCode RedAlert")
top.configure(background="#4339fb")
self.Button1 = tk.Button(top)
self.Button1.place(relx=0.333, rely=0.667, height=54, width=177)
self.Button1.configure(activebackground="#ececec")
self.Button1.configure(activeforeground="#000000")
self.Button1.configure(background="#ffff00")
self.Button1.configure(cursor="fleur")
self.Button1.configure(disabledforeground="#a3a3a3")
self.Button1.configure(font=font14)
self.Button1.configure(foreground="#000000")
self.Button1.configure(highlightbackground="#d9d9d9")
self.Button1.configure(highlightcolor="black")
self.Button1.configure(pady="0")
self.Button1.configure(text='''Clear Alarm''')
self.Text1 = tk.Text(top)
self.Text1.place(relx=0.125, rely=0.133, relheight=0.423, relwidth=0.756)
self.Text1.configure(background="white")
self.Text1.configure(font=font13)
self.Text1.configure(foreground="black")
self.Text1.configure(highlightbackground="#d9d9d9")
self.Text1.configure(highlightcolor="black")
self.Text1.configure(insertbackground="black")
self.Text1.configure(selectbackground="#c4c4c4")
self.Text1.configure(selectforeground="black")
self.Text1.configure(wrap="word")
vp_start_gui()
while 1:
#Receive data from LAN device
reply = s.recv(34)
#Receive replies from SMS Gateway
#smsreply = g.recv(34)
#Check for Lan device keep alive replies
if reply.find(alivereply) != -1:
#print 'Device alive'
print reply
#Check for valid Tag strings
if reply.find(tagstring) != -1:
print 'Tag string received'
print reply
#Send SMS alert message
doorcode = reply[5:6]
doornumber = int(doorcode, 16)
#print doornumber
tagcode = reply[8:9]
tagnumber = int(tagcode, 16)
#print tagnumber
print 'Alert Door ' +str(doornumber) + ' Tag ' +str(tagnumber)