Results 1 to 7 of 7

Thread: Tkinter doubt

  1. #1
    Join Date
    Jul 2007
    Location
    India
    Beans
    449
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Tkinter doubt

    I have a few problems that i am facing with Tkinter, and need help.

    1- My code looks somewhat like this:
    Code:
    def draw(args):
    	#code
    	
    	root.mainloop() #This is where i want my Tkinter window to update, without requiring it to be closed
    	time.sleep(1)
    	
    def main():
    	from Tkinter import *
    
    	root=Tk()
    	while(1):
    		#code
    		draw(args)
    Instead of mainloop, i have identified a method called update, but don't know how it works. Can someone help.

    2- How can you draw a simple table with information on a tkinter canvas.
    Ultimately isn't the world round.

  2. #2
    Join Date
    Jun 2006
    Beans
    2,930

    Re: Tkinter doubt

    Can you post the actual code?
    the code you posted doesn't run.

    main() isn't called
    args is not defined
    root is not passed to draw

    edit: is this more like what you want?
    Code:
    def draw(root):
            import time
    	#code
    	
            root.mainloop() #This is where i want my Tkinter window to update, without requiring it to be closed
            time.sleep(1)
    	
    def main():
    	from Tkinter import *
    
    	root=Tk()
    	while(1):
    		#code
    		draw(root)
    main()
    Last edited by lavinog; October 20th, 2009 at 09:44 PM.
    Support 7z in default installs!!!: Click Here

    How to use code blocks to post command output: Click Here
    Official Ubuntu Documentation

  3. #3
    Join Date
    Jul 2007
    Location
    India
    Beans
    449
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Tkinter doubt

    I am sorry for misguided information(which i assumed) in the code.

    My whole point is, how do we update the Tkinter window, everytime i enter the while loop? In my code that runs, the window updates itself, everytime i close it. Which isn't what i want. I want a self-updating window, every 1 second or something. Can someone please help. My code formation is still somewhat mentioned above.
    Ultimately isn't the world round.

  4. #4
    Join Date
    Jun 2006
    Beans
    2,930

    Re: Tkinter doubt

    I think it would be easier if you had something I could work with.

    I am not understanding why you need the form updated every second.
    Support 7z in default installs!!!: Click Here

    How to use code blocks to post command output: Click Here
    Official Ubuntu Documentation

  5. #5
    Join Date
    Jul 2007
    Location
    India
    Beans
    449
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Tkinter doubt

    It is something like this, Main calls draw. Which does something to the tkinter window, depending on its received arguments. Then time.sleep(1), makes the Tkinter window wait for some time, without undergoing any change. On returning to main, draw is called with a new set of arguments, which should again make changes to the Tkinter screen.

    I want to know, how to update the Tkinter window??(Which should ideally update depending on the sleep time mentioned.)
    Ultimately isn't the world round.

  6. #6
    Join Date
    Jan 2008
    Location
    Raytown, MO
    Beans
    460
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Tkinter doubt

    Quote Originally Posted by i.mehrzad View Post
    I have a few problems that i am facing with Tkinter, and need help.

    ...

    2- How can you draw a simple table with information on a tkinter canvas.
    hmm ... if you want a table - why not look at a table widget, rather than drawing it on a canvas?

    TkTable - http://tkinter.unpythonic.net/wiki/TkTable

    Steve
    (PS - with Tk, you should avoid update whenever possible, FWIW)
    The Tcler's Wiki http://wiki.tcl.tk Tcl Developer Exchange http://www.tcl.tk SQLite http://www.sqlite.org

  7. #7
    Join Date
    Jul 2007
    Location
    India
    Beans
    449
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Tkinter doubt

    The purpose of, root.mainloop() is to display the top level widget, root, along with all the widgets packaged in it.

    Is root.update(), a replacement for root.mainloop(), except that 'root' will update itself, everytime this statement is executed.
    Is this thinking correct??

    One more problem i am facing, is where should, root.mainloop() be located in the program. Is it allright if it is encountered once, i.e. at the end of the entire program.

    Can someone please help, i have an assignment which has to be submitted on the coming weekend, and can't seem to figure this out.
    Ultimately isn't the world round.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •