why tkinter start stop infinite loop doesn't process

Thread Starter

pretty_fly

Joined Feb 2, 2015
21
I want to start an infinite loop after pressing START button. But I' m having problem for giving the initial values for the internal index. After the loop started it must change the value of j to bigger than 0 and the loop will perform other tasks. However this doesn't happen and the loop doesn't enter "elif" section. So could you give some help how to process this loop ?

This is the main part of the whole gui code.

Python:
from Tkinter import *
import serial
from threading import Timer

port = serial.Serial('/dev/ttyUSB0', 115200)

PC1 = open("File_1.txt","a")
PC2 = open("File_2.txt","a")
PC3 = open("File_3.txt","a")
PC4 = open("File_4.txt","a")
PC5 = open("File_5.txt","a")
PC6 = open("File_6.txt","a")
PC7 = open("File_7.txt","a")
PC8 = open("File_8.txt","a")


HMCC=Tk()

HMCC.title(" GUIs v1.0 ")
HMCC.geometry("750x500")

control_var = 0

def start():
    global t
    t=Timer(1,start)
    t.start()
    print("Data Transmission started ... ! ")
    global control_var
    control_var= 1
  
  
def stop():
    global control_var
    control_var = 0
    global t
    if t:
        t.cancel()  


def scanning():
    j=0
    k=0
    m=[]
    ii=0
    global control_var

    if control_var == 1 :

        print "Running..."
      
        raw_data     = ord(port.read())
        bin_raw_data = bin(raw_data)[2:].zfill(8)
        print(raw_data)
      
        if raw_data==127:  
            k=0
            j=j+1
            print '\n-----',j,'------------------------------ \n'
            m=[]
      
        elif j > 0 :
          
            m.append(bin_raw_data)
            k=k+1
            if k == 24    :  
                for ii in range(0,8) :
                  
                    Count_bin=m[ii*3]+m[ii*3+1]+m[ii*3+2]
                    Count=int(Count_bin,2)
                  
                    print 'Channel:',ii+1,'  ' , Count
                  
                    if   ii==0:  
                        PC1.write(str(Count) + "\n")
                        count_1.config(raw_data)                      
                    elif ii==1:  
                        PC2.write(str(Count) + "\n")
                        count_2.config(raw_data)                      
                    elif ii==2:  
                        PC3.write(str(Count) + "\n")
                        count_3.config(raw_data)                      
                    elif ii==3:  
                        PC4.write(str(Count) + "\n")
                        count_4.config(raw_data)                      
                    elif ii==4:  
                        PC5.write(str(Count) + "\n")
                        count_5.config(raw_data)                      
                    elif ii==5:  
                        PC6.write(str(Count) + "\n")
                        count_6.config(raw_data)                      
                    elif ii==6:  
                        PC7.write(str(Count) + "\n")
                        count_7.config(raw_data)                      
                    elif ii==7:
                        PC8.write(str(Count) + "\n")
                        count_8.config(raw_data)                      
  

count_1 = Label(HMCC)
count_2 = Label(HMCC)
count_3 = Label(HMCC)
count_4 = Label(HMCC)
count_5 = Label(HMCC)
count_6 = Label(HMCC)
count_7 = Label(HMCC)
count_8 = Label(HMCC)

count_1.place(relx=.6, rely=.1, anchor="c")
count_2.place(relx=.6, rely=.2, anchor="c")
count_3.place(relx=.6, rely=.3, anchor="c")
count_4.place(relx=.6, rely=.4, anchor="c")
count_5.place(relx=.6, rely=.5, anchor="c")
count_6.place(relx=.6, rely=.6, anchor="c")
count_7.place(relx=.6, rely=.7, anchor="c")
count_8.place(relx=.6, rely=.8, anchor="c")


Channel_1 = Label(HMCC, text = "Channel 1 : ")
Channel_2 = Label(HMCC, text = "Channel 2 : ") 
Channel_3 = Label(HMCC, text = "Channel 3 : ")
Channel_4 = Label(HMCC, text = "Channel 4 : ")
Channel_5 = Label(HMCC, text = "Channel 5 : ")
Channel_6 = Label(HMCC, text = "Channel 6 : ")
Channel_7 = Label(HMCC, text = "Channel 7 : ")
Channel_8 = Label(HMCC, text = "Channel 8 : ")

Channel_1.place(relx=.4, rely=.1, anchor="c")
Channel_2.place(relx=.4, rely=.2, anchor="c")
Channel_3.place(relx=.4, rely=.3, anchor="c")
Channel_4.place(relx=.4, rely=.4, anchor="c")
Channel_5.place(relx=.4, rely=.5, anchor="c")
Channel_6.place(relx=.4, rely=.6, anchor="c")
Channel_7.place(relx=.4, rely=.7, anchor="c")
Channel_8.place(relx=.4, rely=.8, anchor="c")

button1 = Button(text="   START   " , fg="black"  ,command=start )
button2 = Button(text=" PAUSE "     , fg="black" )
button3 = Button(text="    STOP    ", fg="black",command=stop)
button4 = Button(text="QUIT"        , fg="black",command=HMCC.quit)

button1.place(relx=.1, rely=.2, anchor="c")
button2.place(relx=.1, rely=.3, anchor="c")
button3.place(relx=.1, rely=.4, anchor="c")
button4.place(relx=.1, rely=.5, anchor="c")



HMCC.mainloop()

PC1.close()
PC2.close()
PC3.close()
PC4.close()
PC5.close()
PC6.close()
PC7.close()
PC8.close()
Thanks in advance ...
 
Last edited:

Motanache

Joined Mar 2, 2015
474
If you want, please, attach this piece of code as a small program that can be compiled.

Also indicates the compiler.
I would like to compile it too.
 

Thread Starter

pretty_fly

Joined Feb 2, 2015
21
If you want, please, attach this piece of code as a small program that can be compiled.

Also indicates the compiler.
I would like to compile it too.
Hi @Motanache

Thank you for your interest.
I've uploaded the complete GUI script. I just type "sudo python name_of_the_script.py" to open the GUI.
 

Motanache

Joined Mar 2, 2015
474
Unfortunately, I was unable to run it.You also use a USB-serial converter.
py.png
I do not think I can answer.
 
Last edited:
Top