In python 2.7 if i click a button when a loop is running IDLE stops working till python comes out of the loop. I've attached my entire code as I don't have any idea why would this be happening.
import time
import Tkinter as tk
from Tkinter import StringVar
import threading
x="False"
def xval(*args):
for i in range(0,9):
global x
if(x=="False"):
print "x=false %d time"%i
time.sleep(1)
def stop(event):
resume_btn.configure(state="normal")
global x
x ="True"
print "execution stopped:%s"%x
def start(event):
global x
x ="False"
print "execution started:%s"%x
xval()
root = tk.Tk()
th = threading.Event()
t = threading.Thread(target=xval,args=(th,))
t.deamon=True
t.start()
x_btn = tk.Button(root, text="Stop", background="Snow", width=20)
x_btn.grid(row=0, column=4, sticky="W", padx=20, pady=5)
x_btn.bind('<Button-1>',stop)
resume_btn = tk.Button(root, text="Start", background="Snow", width=20)
resume_btn.configure(state="disabled")
resume_btn.grid(row=0, column=6, sticky="W", padx=20, pady=5)
resume_btn.bind('<Button-1>',start)
root.mainloop()
Here both buttons work fine in first go but second time neither the value of x gets updated when I click on stop nor the button works till python comes out of the loop. Can anybody tell why this is happening.