Tkinter problem with loops

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stknightmare
    New Member
    • Oct 2007
    • 2

    Tkinter problem with loops

    Hi i have a program written in python which uses very big loops and i am trying to get some output by using the text widget of tkinter,the problem is that tkinter waits for the function to finish the loop before showing any result at all.Is there any way to make the program show some output even though the program loop is not yet finished?

    OS: Linux

    Code:
    from Tkinter import *
    
    root=Tk()
    root2=Tk()
    text="1"
    x=0
    def remove():	
    	if text != '1':
    		text.grid_remove()
    
    def clear():
    	global text
    	global x
    	remove()
    	
    	while 1:
    		text=Text(root2,height=1,width=70)
    		text.insert(END,"test%d"%(x))
    		text.grid(row=1,column=1)
    		x+=1	
    		
    			
    execute=Button(root,text="execute",command=clear)
    execute.grid()
    
    root.geometry("+100+200")
    root2.geometry("+500+100")
    
    root.mainloop()
  • KaezarRex
    New Member
    • Sep 2007
    • 52

    #2
    Originally posted by stknightmare
    Hi i have a program written in python which uses very big loops and i am trying to get some output by using the text widget of tkinter,the problem is that tkinter waits for the function to finish the loop before showing any result at all.Is there any way to make the program show some output even though the program loop is not yet finished?

    OS: Linux

    Code:
    from Tkinter import *
    
    root=Tk()
    root2=Tk()
    text="1"
    x=0
    def remove():	
    	if text != '1':
    		text.grid_remove()
    
    def clear():
    	global text
    	global x
    	remove()
    	
    	while 1:
    		text=Text(root2,height=1,width=70)
    		text.insert(END,"test%d"%(x))
    		text.grid(row=1,column=1)
    		x+=1	
    		
    			
    execute=Button(root,text="execute",command=clear)
    execute.grid()
    
    root.geometry("+100+200")
    root2.geometry("+500+100")
    
    root.mainloop()
    Try using this statement whenever you want to show the output:
    [CODE=python]root.update()[/CODE]

    Comment

    • stknightmare
      New Member
      • Oct 2007
      • 2

      #3
      Thank you very much.It worked.

      Comment

      Working...