Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Tkinter program crashes (http://www.velocityreviews.com/forums/t321024-tkinter-program-crashes.html)

srijit@yahoo.com 08-14-2003 05:55 PM

Tkinter program crashes
 
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

Russell E. Owen 08-14-2003 09:17 PM

Re: Tkinter program crashes
 
In article <221d8dbe.0308140955.658000d0@posting.google.com >,
srijit@yahoo.com 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()

srijit@yahoo.com 08-16-2003 02:08 AM

Re: Tkinter program crashes
 
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()

Chad Netzer 08-21-2003 07:00 AM

Re: Tkinter program crashes
 
On Thu, 2003-08-14 at 10:55, srijit@yahoo.com 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




All times are GMT. The time now is 12:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.