Click on New Code in the previous post - it's a link.paully323 wrote:Where can I download the code?
I guess probably "yes". But see my "edit" above. It is evidently a "bug" in the raspbian code because it happens in many other places too. For example while using Chromium browser the cursor often disappears when I click on some text. Then it re-appears when I move the mouse. BTW: I love your tkinter - will be studying the usage in depth!scotty101 wrote:1. Does this happen with all python tkinter GUIs?
Sorry I didn't see this.zjjackson101 wrote: ↑Tue Jul 10, 2018 7:56 pmHi i am trying to use this to debug some python scripts.
I opened your gpioGUI using python3 gpioGUI.py
then in my editor on the pi(Thonny) i ran my script which basically sets pins as high or low based on my input. I can see that the pins are changing on my scope however the gpioGUI does not update to match the pins new state.
Is gpioGUI only for control? ie i cant use it to monitor pin state when testing other scripts?
Code: Select all
# PyMon.py # Program to monitor GPIO pins on a raspberry pi # can be run on the pi or a remote machine # It uses pigpio and needs the pigpiod deamon # to be running on the target machine. # Change the host variable to suit your needs. # If you are running the monitor on the pi # use 'localhost' # written by Roger Woollett import sys if(sys.version_info < 3): import Tkinter as tk import ttk import tkMessageBox as mb import tkSimpleDialog as sd else: import tkinter as tk import tkinter.ttk as ttk import tkinter.messagebox as mb import tkinter.simpledialog as sd import socket as s import pigpio as pg # pigpiod daemon location # This really should be configured by user host = 'boromir' port = 8888 REFRESH_RATE = 200 # msec between updates COLS = 5 # columns in display TITLE = 'Python GPIO Monitor' # Pins to test (Broadcom,physical) # N.B. this list is for B+ & A+ earlier pis do not have so many pins pins = ((2,3),(3,5),(4,7),(5,29),(6,31),(7,26),(8,24), (9,23),(10,19),(11,23),(12,32),(13,33),(14,8), (15,10),(16,36),(17,11),(18,12),(19,35),(20,38), (21,40),(22,15),(23,16),(24,18),(25,22),(26,37),(27,13)) class Config(sd.Dialog): def __init__(self,master,msg,*args,**kwargs): self.msg = msg + '\nPress OK to reconfigure, Cancel to end\n' # body is called by base class __init__ # so call it after self variables are set sd.Dialog.__init__(self,master,*args,**kwargs) def body(self,master): # I am not sure why fist param is master not self ttk.Label(master,text = self.msg).grid(row = 0) ttk.Label(master,text = 'Host:').grid(row = 1,column = 0,sticky = tk.E) ttk.Label(master,text = 'Port:').grid(row = 2,column = 0,sticky = tk.E) global host self.s1 = tk.StringVar() self.s1.set(host) self.e1 = ttk.Entry(master,textvariable = self.s1) self.e1.grid(row = 1,column = 1) global port self.s2 = tk.StringVar() self.s2.set(port) self.e2 = ttk.Entry(master,textvariable = self.s2) self.e2.grid(row = 2,column = 1) return self.e1 def apply(self): global host global port global restart host = self.e1.get() port = int(self.e2.get()) restart = True # A round 'light' that is red if the pin is high (on) class Light(tk.Canvas): def __init__(self,master,*args,**kwargs): tk.Canvas.__init__(self,master,*args,**kwargs) self.id = self.create_oval(5,5,15,15,fill = 'white') def off(self): self.itemconfigure(self.id,fill = 'white') def on(self): self.itemconfigure(self.id,fill = 'red') # A frame for the widgets that show one pin class PinFrame(tk.Frame): def __init__(self,master,pin,phys,*args,**kwargs): tk.Frame.__init__(self,master,*args,**kwargs) self.pin = pin self.mask = 1<<pin self.high = False # create a label (shows GPIO with physical pin no in brackets) self.lab = ttk.Label(self,width = 11, text = 'GPIO ' + str(self.pin) + '(' + str(phys) + ')') self.lab.grid(row = 0,column = 0) # create a Light self.light = Light(self,height = 20,width = 30) self.light.grid(row = 0,column = 1) # check to see if state has changed and switch light if needed def check(self,mask): now = mask & self.mask if(now != self.high): self.high = now if(now): self.light.on() else: self.light.off() # a Mainframe object contains the widgets that make up the user interface class Mainframe(tk.Frame): def __init__(self,master,*args,**kwargs): tk.Frame.__init__(self,master,*args,**kwargs) no = len(pins) self.pinframes =  # lay out the frames that show pin status i = 0 row = 0 while(i < no): for col in range(COLS): if i < no: pf = PinFrame(self,pins[i],pins[i]) pf.grid(row = row,column = col) self.pinframes.append(pf) i += 1 row += 1 # I like to have a quit button ttk.Button(self,text = 'Quit',command = master.onQuit).grid(row = 10) self.getpins() # called every REFRESH_RATE msec to update the display def getpins(self): mask = pi.read_bank_1() for i in range(len(self.pinframes)): self.pinframes[i].check(mask) i += 1 # set up the next call self.after(REFRESH_RATE,self.getpins) # a single App object represents the program itself # it has a Mainframe which handles the UI class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) # trap close (X) button so we can cleanup self.protocol('WM_DELETE_WINDOW',self.onQuit) # do cosmetics to main window self.title(TITLE) # check to see if we can talk to the pigpio daemon if(not self.checkdaemon(host,port)): self.onQuit() return # if we get here we think all is well so create the pi object global pi pi = pg.pi(host,port) Mainframe(self).grid() def checkdaemon(self,host,port): # check to see if the target machine is on the network # and the demon seems to be running # returns False if there is an error # first see if host is on network try: # n.b.on a raspberry pi this can take a long time to fail s.gethostbyname(host) except: #mb.showerror('pigpio',"Cannot find host " + host) self.withdraw() Config(self,"Cannot find host " + host) # abort program return False else: # now see if daemon is running try: sock = s.create_connection((host,port)) except: #mb.showerror('pigpio',"Daemon not running on" + host) self.withdraw() Config(self,"Daemon not running on port " + str(port)) return False else: sock.close() return True # clean up and exit def onQuit(self): self.destroy() if(pi != None): pi.stop() restart = True while restart: restart = False # communicates with pigpiod running on the # raspberry pi. pi = None # create an App object and execute its main loop App().mainloop()