I was trying to use the "Start" and "Stop" button in GUI using Tkinter. I am using Raspberry Pi 3 and python 2.7 version, start button is working properly, stop button is not working. Someone, please suggest some solution. Thanks Mehnaz
from __future__ import print_function, division
import os, sys, inspect, platform
import time
import serial # import Serial Library
import numpy # Import numpy
import csv # import csv module
import os
import scipy
#import Figtodat
#from images2gif import writeGif
#matplotlib.use('Agg')
import matplotlib.pyplot as plt #import matplotlib library
from drawnow import *
from collections import OrderedDict
#from detect_peaks import detect_peaks
from Tkinter import *
os.getcwd()
ruing = True
def Data_Acquisition():
def scaing():
if ruing:
ser = serial.Serial('/dev/ttyUSB1',9600, 8, 'N', 1, timeout = 1)
# Open ve_direct.csv
file_data = open(Patient_Name+'.csv', 'w')
print "Reading data and writing to ve_data.csv"
# Listen for the input, exit if nothing received in timeout period
output = " "
while True:
output = " "
while True:
while output != "":
output = ser.readline()
file_data.write(output)
print output,
output = " "
# close file
print ("Stopped writing to ve_data.csv")
file_data.close()
def start():
global ruing
ruing = True
def stop():
global ruing
ruing = False
root = Tk()
root.title('Elbonix')
root.geometry("800x480")
app = Frame(root)
app.grid()
start = Button(app,text="Start Scan", command=scaing)
stop = Button(root,text="Stop", command=stop)
start.grid()
stop.grid()
root.mainloop()
ser.close()
file_data.close()
root.mainloop()
def Enter_Patient_Name():
#print("First Name: %s" % e1.get())
master = Tk()
master.title('Elbonix')
Label(master, text="Enter Patient's Name" ,font=("Helvetica", 10, "bold italic"), fg="blue").grid(row=0)
Label(master, text="Ex- LastnameFirstnameDate", font =("Helvetica", 10, "bold italic"), fg="dark grey").grid(row=1)
e1 = Entry(master)
e1.grid(row=2, column=0)
def Continue_scaing():
global Patient_Name
Patient_Name = e1.get()
Data_Acquisition()
Button(master, text='Continue', font=("Helvetica", 10, "bold italic"), fg="white",bg="lime green",command=Continue_scaing).grid(row=3, column=0, sticky=W, pady=4)
Button(master, text='Go back',font=("Helvetica", 10, "bold italic"), fg="white", bg='red' ,command=homeblock).grid(row=3, column=1, sticky=W, pady=4)
print(e1.get())
master.mainloop()
