Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    85
    Rep Power
    9

    Tkinter...Function...Problem


    im usin Tk as my gui module...
    ...........skippin the opening procedures........

    Code:
    def delay():
       from time import sleep
       seconds = (5,0, -1)
       for num in seconds:
          print num
          sleep(1)
          if num == 1:
             print 'HAPPY NEW YEARS!!!!!!!!!!!!!!!!!!!!'
    
    lb1 = Label(app, text='new years begin in...' + str(delay))
    lb1.grid()
    i originally had it set up to where if u pressed the begin button it wus begin...but i want it to happen automatically when the program starts
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Python Code:
     
    from Tkinter import *
    import time
     
    def delay():
        for i in range(5,0,-1):
            l["text"] = i
            root.update()
            time.sleep(1)
        l["text"] ="Happy new year!"
     
    root = Tk()
    l = Label()
    l.pack()
    delay()
    root.mainloop()


    Regards, mawe
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    or you can make it with IntVar()
    Those people who think they know everything are a great annoyance to those of us who do.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    85
    Rep Power
    9
    hey ty man ill try that way out...what does root.update() do exactly....umm well my real question how do u kno when to use it???

    Originally Posted by monkeyman23555
    or you can make it with IntVar()
    hey M.M. can u show me that IntVar() again....with the lil bit of code i gave u so i can c it in real life situation

    PS- how u get the "CODE" box to say Python code or HTML code or any code....ty in adv.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    okay

    em the root.update() i don't think you have to use...

    Var = IntVar(root)
    Var.set(100)
    print Var.get()
    100
    Those people who think they know everything are a great annoyance to those of us who do.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    Originally Posted by RC2001
    what does root.update() do exactly.
    Here is what pydoc says:
    Originally Posted by pydoc
    Enter event loop until all pending events have been processed by Tcl.
    Okay? I don't know this exactly, but if something changes in the GUI (like the text on a label), then update() refreshes the GUI (and you can see the change). So if you don't use it, the GUI just freezes until the loop (in delay here) is over.

    And here's a version with a StringVar() (which might be better here than the IntVar monkeyman suggested):
    Python Code:
     
    from Tkinter import *
    import time
     
    def delay():
        for i in range(5,0,-1):
            text.set(str(i))
            root.update()
            time.sleep(1)
        text.set("Happy new year!")
     
    root = Tk()
    text = StringVar()
    l = Label(textvariable=text)
    l.pack()
    delay()
    root.mainloop()


    You can get the code highlighted, if you use [ highlight=Python]...[ /highlight] tags.

    Regards, mawe
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    85
    Rep Power
    9
    what causes a <function delay at 0x40179d84>

    i got this when i tried sumthin
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    could you show us the whole error
    Those people who think they know everything are a great annoyance to those of us who do.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    85
    Rep Power
    9
    Originally Posted by monkeyman23555
    could you show us the whole error
    that is the whole error...its displayed inside the entry widget...i tried to used a function delay() as StringVar.set(delay)...thas what causes the error.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Originally Posted by RC2001
    as StringVar.set(delay)
    That's nonsense
    StringVar is a class and you have to create an object of this class. Then you can use the method set() on this object
    Code:
    s = StringVar()
    s.set(whatever)
    Also set() wants a value as its argument. delay is a function. Why don't you do it as I showed in my second snippet?
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    thats really wierd that it is displayed in the entry widget
    Those people who think they know everything are a great annoyance to those of us who do.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    85
    Rep Power
    9
    mawe u kno i dont no y either it looked confusin at 1st but im actually studyin it n it fairly understandable umm yea imma do it now...can u explain y my method doesnt wrk properly...lol ill better if i kne y instead of jus stealin ur lil script of the correct way ty
  24. #13
  25. Caress me down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    Pennsylvania
    Posts
    289
    Rep Power
    511
    first of all speek english man... i cant understand what you are trying to say half the time. wen u rite like dis ittis confusin.

    now post all of your code because at this moment i have no idea of what you have and what you are trying to do. post the whole thing too (including the opening procedures as you refer to them).
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    85
    Rep Power
    9
    well turns out mawe ur way is nicer umm lol now i gotta figure out how to make it so the GUI cant be [X] out...almost as a it will not close until the program runs fully...ill research that
  28. #15
  29. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    The way you are typing and expressing your words is confusing me greatly. You may want to look into the atexit module.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo