Tkinter program crashes

Discussion in 'Python' started by srijit@yahoo.com, Aug 14, 2003.

  1. Guest

    Hello,

    Any idea - why the following code crashes on my Win 98 machine with
    Python 2.3? Everytime I run this code, I have to reboot my machine.
    I also have Win32all-157 installed.

    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()


    Regards,
    Srijit
    , Aug 14, 2003
    #1
    1. Advertising

  2. In article <>,
    wrote:

    >Any idea - why the following code crashes on my Win 98 machine with
    >Python 2.3? Everytime I run this code, I have to reboot my machine.
    >I also have Win32all-157 installed.


    I can see no errors in the code. Also, I tried it on unix and Mac and it
    ran fine. I suspect there's a problem with your installation of Python,
    Tkinter or Tcl/Tk.

    I do have a few style complaints. It is silly to worry about style when
    the program is crashing, but I've appended them (along with a modified
    sample program) in case you may be interested at some point.

    -- Russell

    Suggested style changes:
    - the frame isn't being used for anything so you might as well just pack
    the widgets into the master. But it would be much better to have App
    subclass Frame so App acts like any other Tkinter widget. You can then
    mix App with other widgets to make larger widgets. (One minor drawback
    is you have to grid or pack it once you create it -- just like any other
    Tkinter widget).

    - Use "import Tkinter" instead of "from Tkinter import *" for anything
    except trivial code. It makes for more typing, but cuts down on
    namespace pollution -- especially useful if you start subclassing
    Tkinter classes.

    - The say_hi method might as well be locally defined. I suggest you only
    create class methods if they need data from the class or if users of the
    class might find them handy.

    Here's a version incorporating those changes. The if __name__ stuff at
    the bottom allows you to import this module and use App as a widget.

    import Tkinter

    class App(Tkinter.Frame):
    def __init__(self, master):
    Tkinter.Frame.__init__(self, master)

    self.button = Tkinter.Button(
    self, text="QUIT", fg="red", command=self.quit)
    self.button.pack(side=Tkinter.LEFT)

    def say_hi():
    print "hi there, everyone!"

    self.hi_there = Tkinter.Button(
    self, text="Hello", command=say_hi)
    self.hi_there.pack(side=Tkinter.LEFT)

    if __name__ == "__main__":
    root = Tkinter.Tk()

    app = App(root)
    app.pack()

    root.mainloop()
    Russell E. Owen, Aug 14, 2003
    #2
    1. Advertising

  3. Guest

    Hello Members,

    Here are the details of Python Tkinter applications crash on my
    machine (Win 98, Python 2.3 and Win32all-157).

    This has happened whenever I try to run a Tkinter application. The
    application runs fine. The problem happens whenever I exit from the
    Tkinter application.
    This was happening with Python 2.3b1. It continued to happen when I
    uninstalled Python 2.3b1 and installed python 2.3.

    The only exception is IDLE. IDLE is also a Tkinter application. Other
    Python applications are yet to give problems. For example I was
    successful in running PyGTK applications on my same setup.

    For example when I ran the Tkinter code (refer below for the actual
    code) and exited from the application I got the following message.

    PYTHON caused an invalid page fault in
    module KERNEL32.DLL at 0167:bff7b9a6.
    Registers:
    EAX=00000000 CS=0167 EIP=bff7b9a6 EFLGS=00000246
    EBX=011033a0 SS=016f ESP=0062f878 EBP=0062f888
    ECX=01103370 DS=016f ESI=01105a98 FS=3c4f
    EDX=7efeff73 ES=016f EDI=01103370 GS=0000
    Bytes at CS:EIP:
    ff 76 04 e8 13 89 ff ff 5e c2 04 00 56 8b 74 24
    Stack dump:
    0110484c 010f274f 01105a98 0000002e 0062f8d4 010f0c79 00000009
    01103370 0062f98d 010f0c48 0000002e 010ef913 0000002e 00000001
    010d9f40 0000002e

    I am unable to figure out the problem. I guess re-installing Python
    2.3 will not help.
    I hope somebody will help me to run Tkinter applications comfortably
    on my machine. Otherwise I have to live without Tkinter applications
    (except IDLE) on my machine.
    I also know it does not happen on Win 2000 or Win XP. Now I cannot
    afford Win 2000 or XP.

    Regards,
    Srijit

    The Tkinter code which crashed my Win 98 machine is :

    import Tkinter

    class App(Tkinter.Frame):
    def __init__(self, master):
    Tkinter.Frame.__init__(self, master)

    self.button = Tkinter.Button(
    self, text="QUIT", fg="red", command=self.quit)
    self.button.pack(side=Tkinter.LEFT)

    def say_hi():
    print "hi there, everyone!"

    self.hi_there = Tkinter.Button(
    self, text="Hello", command=say_hi)
    self.hi_there.pack(side=Tkinter.LEFT)

    if __name__ == "__main__":
    root = Tkinter.Tk()

    app = App(root)
    app.pack()

    root.mainloop()
    , Aug 16, 2003
    #3
  4. Chad Netzer Guest

    On Thu, 2003-08-14 at 10:55, wrote:
    > Hello,
    >
    > Any idea - why the following code crashes on my Win 98 machine with
    > Python 2.3?


    > self.button = Button(
    > frame, text="QUIT", fg="red", command=frame.quit



    Rather than "frame.quit", could you try "sys.quit", to see if it makes a
    difference?

    --

    Chad Netzer
    Chad Netzer, Aug 21, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ahmad
    Replies:
    1
    Views:
    1,913
    Gernot Frisch
    Jan 12, 2005
  2. Gary Richardson

    Bug 834351 - Mouse wheel crashes program

    Gary Richardson, Dec 8, 2004, in forum: Python
    Replies:
    2
    Views:
    284
    Adonis
    Dec 10, 2004
  3. Earl Eiland
    Replies:
    0
    Views:
    328
    Earl Eiland
    Mar 18, 2005
  4. Earl Eiland
    Replies:
    0
    Views:
    372
    Earl Eiland
    Mar 19, 2005
  5. Replies:
    0
    Views:
    273
Loading...

Share This Page