Python Tkinter: Reading Serial Values
Question: I would like to read serial values into my Tkinter GUI. Either into a text
window or eventually to a text label widget which updates every second or so.
The issue I am having is with the queue class. The error I am getting is:
AttributeError: 'Applcation' object has no attribute 'queue'

Here is my code:

    
    
    #!/usr/bin/env python
    
    from tkinter import *
    from tkinter import messagebox
    from time import sleep
    import picamera
    import os
    import serial
    import sys
    import RPi.GPIO as GPIO
    import _thread
    import threading
    import random
    import queue
    
    # Setup GPIO pin(s) 
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(18, GPIO.OUT)
    GPIO.output(18, False)
    
    
    #==============================================================
    # Declaration of Constants
    # none used
    
    #==============================================================
    
    class SerialThread(threading.Thread):
        def __init__(self, queue):
            threading.Thread.__init__(self)
            self.queue = queue.Queue()
    
        def read_sensor_values(self):
            ser = serial.Serial('/dev/ttyUSB0', 9600)
            while True:
                if ser.inWaiting:
                    text = ser.readline(s.inWaiting)
                    self.queue.put(text)
                    self.pressures_txt.insert(0.0,values)
    
    
    
    
    
    
    class Application(Frame):
        """ GUI Application for taking photos. """
    
        def __init__(self, master):
            super(Application, self).__init__(master)  
            self.grid()
            self.create_widgets()
            self.setup_camera()
    
        def create_widgets(self):
    
        Checkbutton( self, text = "Read Pressure Values", variable = self.mode2, command = self.process_serial, bg = 'white').grid(row = 4, column = 0, sticky = W+E+N+S)
    
        # create text field to display pressure values from arduino
            self.pressures_txt = Text(self, height = 3, wrap = WORD)
            self.pressures_txt.grid(row=9, column = 0, columnspan =3)
    
        def process_serial(self):
            #self.text.delete(1.0, END)
            while self.queue.qsize():
                try:
                    self.text.insert(END, self.queue.get())
                    self.pressures_txt.insert(0.0, self.queue.get())
                except queue.Empty:
                    pass
            self.after('1000', self.process_serial)
         #................. end of method: read_sensor_values ................
    
    
    #=================================================================
    # main
    #=================================================================
    
    root = Tk()                             # Create the GUI root object
    root.title("Control V1.0")
    app = Application(root)                 # Create the root application window
    root.mainloop()
    

The code I have posted is an abbreviated version of the entire program. I have
removed sections that are supposedly irrelevant. I am running in python3. I
suspect I may have an error in indentation but I am not certain.

I am using the code from the following link for my serial reading class:

<https://www.daniweb.com/programming/software-
development/threads/496499/using-a-checkbutton-to-import-serial-data-into-
python-tkinter>


Answer: The problem is that the `self.queue` in `read_sensor_values` belongs to a
`SerialThread` object. When you say `self.queue` in the `process_serial`
method of your `Application` object, it refers to a non-existent `queue`
attribute of the `Application` object. Perhaps you ought to make the
`SerialThread` object an attribute of your `Application` object. Then
`process_serial` could refer to `self.serial.queue` or whatever you name it.

