python tkinter怎么读_Python Tkinter:读取序列值

我想把串行值读入我的Tkinter图形用户界面。或者进入一个文本窗口,或者最终到一个每隔一秒更新一次的文本标签小部件。我遇到的问题是队列类。我得到的错误是:

AttributeError:“application”对象没有属性“queue”

这是我的代码:#!/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()

我发布的代码是整个程序的缩写版本。我删除了那些被认为不相关的部分。我穿着Python3跑。我怀疑我的缩进可能有错误,但我不确定。在

我正在使用以下链接中的代码进行我的系列阅读课:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值