473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

tkinter shell problem

Hi,

I have the following problem:

I wrote a tkinter shell which on a key return event first evals the input
buffer (in a try: except:) and then, in case of except, execs the input
buffer.
I have the problem if the exec fails:

If I trap it, I do not get the stack dump that I which I would show.

ex:

% import dontexist

Traceback (most recent call last):
File "<pyshell#3>", line 1, in -toplevel-
import dontexist
ImportError: No module named dontexist
If I don"t trap it, then my clean up code which is after the exec obviously
does not get called (i.e, clear my input buffer, save the history, print a
prompt .......)

Yet Idle manages - any clue ?
Regards,

Philippe


Jul 18 '05 #1
2 1468
Philippe C. Martin wrote:
Hi,

I have the following problem:

I wrote a tkinter shell which on a key return event first evals the input
buffer (in a try: except:) and then, in case of except, execs the input
buffer.
I have the problem if the exec fails:

If I trap it, I do not get the stack dump that I which I would show.


Why? When catching an exception, you can get the exception type, the exception
itself and the traceback object via the sys.exc_info() function. You can then
use the traceback module to format the traceback just as Python would print it
if the exception went to the top-most level.

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Jul 18 '05 #2
In article <ma**************************************@python.o rg>,
"Philippe C. Martin" <ph*************@sbcglobal.net> wrote:
Hi,

I have the following problem:...
If I trap (an exception), I do not get the stack dump that I which I would show.
...
If I don"t trap it, then my clean up code...does not get called...

Yet Idle manages - any clue ?


Use the traceback module. For example:

try:
...code to protect...
except (SystemExit, KeyboardInterrupt):
raise
except Exception, e:
traceback.print_exc(file=sys.stderr)
....code to handle exception...

if you are sure none of your code can raise error exceptions that
inherit directly from Exception, you can simplify this to one except:
except StandardError, e:
Unfortunately, some common modules (including Tkinter) raise exceptions
that inherit from Exception, not StandardError.

-- Russell
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tom Locke | last post by:
Hi All, I'm having trouble with the python shell within emacs. It's hanging when I use tkinter. Setup is: Windows XP emacs 21.3 py-mode 4.6 Recipe:
0
by: Todd Miller | last post by:
I'm working on a Tkinter backend for the matplotlib plotting software. matplotlib can be run interactively from some form of Python shell while plotting to a Tk window. One annoyance we've noticed...
2
by: Krzysztof Szynter | last post by:
Hi all Like i said, i'am back. With another problem of course. This is my code: ---BEGIN win=Tkinter.Tk() can=Tkinter.Canvas(win,width=500,height=500,background='blue') can.pack()
4
by: Yann.K | last post by:
Hello. Using Tkinter, i would create a widget which display a shell command return. This return is long, and i would display a real time display (like with the tail -f commande on Linux) I...
2
by: codecraig | last post by:
Hi, I was reading through the Tkinter tutorial at http://www.pythonware.com/library/tkinter/introduction/index.htm ...and it mentions that by doing, from Tkinter import * you have access to...
3
by: Jo Schambach | last post by:
I am trying to write a GUI with tkinter that displays the stdout from a regular C/C++ program in a text widget. The idea i was trying to use was as follows: 1) use "popen" to execute the C/C++...
2
by: Stewart Midwinter | last post by:
this has me puzzled; I've created a small test app to show the problem I'm having. I want to use subprocess to execute system commands from inside a Tkinter app running under Cygwin. When I...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
1
by: jkuo22 | last post by:
Hi everyone, Here is my simple Tkinter script: ## start of entry.py from Tkinter import * root=Tk() e1=Entry(root, width=16) e1.pack() e2=Entry(root, width=16)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.