multithreading - Python Tkinter: Reading Serial Values -


i read serial values tkinter gui. either text window or text label widget updates every second or so. issue having queue class. error getting is: attributeerror: 'applcation' object has no attribute 'queue'

here code:

#!/usr/bin/env python  tkinter import * tkinter import messagebox time import sleep import picamera import os import serial import sys import rpi.gpio 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 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 display pressure values 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 gui root object root.title("control v1.0") app = application(root)                 # create root application window root.mainloop() 

the code have posted abbreviated version of entire program. have removed sections supposedly irrelevant. running in python3. suspect may have error in indentation not certain.

i using code following link serial reading class:

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

the problem self.queue in read_sensor_values belongs serialthread object. when self.queue in process_serial method of application object, refers non-existent queue attribute of application object. perhaps ought make serialthread object attribute of application object. process_serial refer self.serial.queue or whatever name it.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -