#1
  1. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12

    Some very basic Tkinter help


    Hi, I've decided to finally get dirty with Tkinter. Anyway, I grabbed the following code from http://www.pythonware.com/library/tk...ello-again.htm :
    Code:
    # File: hello2.py
    
    from Tkinter import *
    
    class App:
    
        def __init__(self, master):
    
            frame = Frame(master)
            frame.pack()
    
            self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
            self.button.pack(side=LEFT)
    
            self.hi_there = Button(frame, text="Hello", command=self.say_hi)
            self.hi_there.pack(side=LEFT)
    
        def say_hi(self):
            print "hi there, everyone!"
    
    root = Tk()
    
    app = App(root)
    
    root.mainloop()
    Nothing very complicated, that's for sure, but for some reason each time I press the QUIT button, the program goes fubar and I Ctrl-Alt-Del my way out of it. I've tried it on my own PC and our university's and both get the same result. I can't see what could be wrong with the code, so any help/corrections would be appreciated.
    Time is the greatest of teachers ; sadly, it kills all of its students.
    - Hector Berlioz
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I've knowticed the same thing! Your script worked fine on windows XP, but if i took it to 98 or ME the console window would hang like a beast! I havn't tested this on *nix but i think its a TK thing since it doesn't seem to happen with other GUI kits..

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    12
    I've had this problem before, try replaceing frame.quit with frame.destroy.
  6. #4
  7. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    Originally posted by netytan
    I havn't tested this on *nix but i think its a TK thing since it doesn't seem to happen with other GUI kits.
    I've just tried it on Linux, and it works just fine. Weird.

    Baltor : I'll try that... tomorrow. I can barely type now.
    Time is the greatest of teachers ; sadly, it kills all of its students.
    - Hector Berlioz
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Norway
    Posts
    41
    Rep Power
    12
    WinMe/Python 2.2.3

    It worked fine a few times, then it hanged, and I couldn't even kill the dos window or restart the computer via the start menu. I remember having problems earlier when I experimented with some GUI's, and this was the reason I downloaded WxPython. Haven't done anything with WxPython so I don't know if it's any better. But I suspect it is a Tk/WinME problem.
    Good web hosting info - articles about web hosting
    hb's web dev blog
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ok, maybe this is a windows/tk thing then guys . its still there in 2.3 so i don't hold out much hope of it going away any time soon.. Anyone nowtice that it hangs more often when you've printed to the console window? In any case, if your doing anything more complex than messing arround with GUI's i'd really try some of the other great kits like wxWindows and QT. But i'm no TK fan though obviously so

    Mark.
    Last edited by netytan; October 10th, 2003 at 04:45 AM.
    programming language development: www.netytan.com Hula

  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    1
    Rep Power
    0
    I'm trying out Python too and I'm having the same problem with a Windows 98 computer.

    Originally posted by Baltor
    I've had this problem before, try replaceing frame.quit with frame.destroy.
    I tried that, but it still doesn't quite seem to work. The QUIT button will make the buttons disappear, but the window remains. Clicking the close button in the window closes it. I guess that's better than hanging, though.

    Just to mess around, though, I tried changing it to "root.destroy." That seems to work. I'm quite new to Python, so if there's any reason that might a bad idea for some reason, please say so.
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I think the general desision here was that destroy() is just as valid a way to close a widow as quit() and works better.. i wouldn't worry about it and its not going to make any differance to the rest of your programe

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo