#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12

    Tkinter prob.......


    Hi,
    I've started gettimg my feet wet in Tkinter. Just started my first program but encountered a problem.....

    Here's the code.........

    PHP Code:
    >>> from Tkinter import *
    >>> class 
    App:
    ...     
    def __init__(self,master):
    ...         
    frame=Frame(master)
    ...         
    frame.pack()
    ...         
    self.button=Button(frame,text="QUIT",fg="blue",command=frame.quit)
    ...         
    self.button.pack(side=LEFT)
    ...         
    self.click=Button(frame,text="CLICK",command=self.welcome)
    ...         
    self.click.pack(side=LEFT)
    ...     
    def welcome(self):
    ...         print 
    "~~~~~~~~~~~~Welcome to JOHNS HOPKINS~~~~~~~~~~~~~~~~"
    ... 
    >>> 
    root=Tk()
    >>> 
    app=App(root)
    >>> 
    root.mainloop() 
    Everything works fine...but my system gives me a Runtime Error ... whenever I click on QUIT button...and the Tk window stops responding... the CLICK button works fine!

    Thanks,
    Subha
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    My guess is that you are running this from within IDLE?

    Run the code from a shell and it should work fine.

    If you change one line in your __init__ method then your code will work well with IDLE:
    Code:
    self.button=Button(frame,text="QUIT",fg="blue",command=master.destroy)
    The difference (I think) - destroy - erases widgets, if there are no widgets left to maintain the mainloop then the program terminates and usually the TCL/TK interpreter is stopped too.

    Quit tries to stop TK/TCL which happens to be used by the parent process for IDLE.

    grimey
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12
    Originally Posted by Grim Archon
    My guess is that you are running this from within IDLE?
    Yes!

    Your master.destroy worked fine....thank you so much!

    <EDIT> I also got it running from the shell...yippe! </EDIT>
    Thanks,
    Subha

IMN logo majestic logo threadwatch logo seochat tools logo