当我使用pyserial时冻结tkinter

时间:2016-09-13 17:30:42

标签: python tkinter freeze pyserial

我有这个代码的问题,我是python中的新手,问题是:我需要在Python GUI中从arduino接收一些数据,我收到数据并保存在txt文件中,但我的程序冻结我无法回到主窗口。

from Tkinter import *
import tkMessageBox
from sys import *
import serial
from Tkinter import Tk
from tkFileDialog import askopenfile

v0=Tk() 
v0.config(bg="mintcream")                              
v0.geometry("400x300")                                 
v0.title("INFORMATION")
label1=Label(v0, text="INFORMATION",font=("Arial", 18,"bold"), fg= "black", bg="mint cream", anchor=W, justify="center").pack()

def ejecutar(f): v0.after(200,f)            

def recepcion(v0):
       ser=serial.Serial('/dev/ttyUSB0', 9600, timeout=1.0)
       i=0
       while i <= 1000:
              archivo = open('DATA BASE.txt', 'a')
              archivo.write(ser.readline())
              archivo.close()

              i= i+1
       ser.close()

def procesar(v0):
       with open("DATA BASE.txt") as fichero:
              for linea in fichero:
                     print (linea)

##Button
b4=Button(v0,text="RECEIVE DATA", font=("Arial", 8, "bold"), bg=("medium sea green"), command=lambda:recepcionIMPEDANCIA(v0))   
b4.pack()                         
b4.place(bordermode=OUTSIDE, height=50, width=110, relx=0.05, rely=0.4)

v0.mainloop()    

0 个答案:

没有答案