Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e9394a

Browse files
committed
add TkVersion,TclVersion; don't drop in debugger
1 parent 470be14 commit 7e9394a

2 files changed

Lines changed: 40 additions & 84 deletions

File tree

Lib/lib-tk/Tkinter.py

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
import tkinter
44
from tkinter import TclError
5+
from types import *
6+
CallableTypes = (FunctionType, MethodType,
7+
BuiltinFunctionType, BuiltinMethodType,
8+
ClassType, InstanceType)
59

6-
class _Dummy:
7-
def meth(self): return
8-
9-
def _func():
10-
pass
11-
12-
FunctionType = type(_func)
13-
ClassType = type(_Dummy)
14-
MethodType = type(_Dummy.meth)
15-
StringType = type('')
16-
TupleType = type(())
17-
ListType = type([])
18-
DictionaryType = type({})
19-
NoneType = type(None)
20-
CallableTypes = (FunctionType, MethodType)
10+
# Older versions of tkinter don't define these variables
11+
try:
12+
TkVersion = eval(tkinter.TK_VERSION)
13+
except AttributeError:
14+
TkVersion = 3.6
15+
try:
16+
TclVersion = eval(tkinter.TCL_VERSION)
17+
except AttributeError:
18+
TclVersion = 7.3
2119

2220
def _flatten(tuple):
2321
res = ()
@@ -347,10 +345,10 @@ def quit(self):
347345
self.tk.quit()
348346
def _getints(self, string):
349347
if not string: return None
350-
res = ()
351-
for v in self.tk.splitlist(string):
352-
res = res + (self.tk.getint(v),)
353-
return res
348+
return tuple(map(self.tk.getint, self.tk.splitlist(string)))
349+
def _getdoubles(self, string):
350+
if not string: return None
351+
return tuple(map(self.tk.getdouble, self.tk.splitlist(string)))
354352
def _getboolean(self, string):
355353
if string:
356354
return self.tk.getboolean(string)
@@ -438,29 +436,9 @@ def apply_func(self, func, args):
438436
except SystemExit, msg:
439437
raise SystemExit, msg
440438
except:
441-
try:
442-
try:
443-
t = sys.exc_traceback
444-
while t:
445-
sys.stderr.write(
446-
' %s, line %s\n' %
447-
(t.tb_frame.f_code,
448-
t.tb_lineno))
449-
t = t.tb_next
450-
finally:
451-
sys.stderr.write('%s: %s\n' %
452-
(sys.exc_type,
453-
sys.exc_value))
454-
(sys.last_type,
455-
sys.last_value,
456-
sys.last_traceback) = (sys.exc_type,
457-
sys.exc_value,
458-
sys.exc_traceback)
459-
import pdb
460-
pdb.pm()
461-
except:
462-
print '*** Error in error handling ***'
463-
print sys.exc_type, ':', sys.exc_value
439+
import traceback
440+
print "Exception in Tkinter callback"
441+
traceback.print_exc()
464442

465443
class Wm:
466444
def aspect(self,

Lib/tkinter/Tkinter.py

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
import tkinter
44
from tkinter import TclError
5+
from types import *
6+
CallableTypes = (FunctionType, MethodType,
7+
BuiltinFunctionType, BuiltinMethodType,
8+
ClassType, InstanceType)
59

6-
class _Dummy:
7-
def meth(self): return
8-
9-
def _func():
10-
pass
11-
12-
FunctionType = type(_func)
13-
ClassType = type(_Dummy)
14-
MethodType = type(_Dummy.meth)
15-
StringType = type('')
16-
TupleType = type(())
17-
ListType = type([])
18-
DictionaryType = type({})
19-
NoneType = type(None)
20-
CallableTypes = (FunctionType, MethodType)
10+
# Older versions of tkinter don't define these variables
11+
try:
12+
TkVersion = eval(tkinter.TK_VERSION)
13+
except AttributeError:
14+
TkVersion = 3.6
15+
try:
16+
TclVersion = eval(tkinter.TCL_VERSION)
17+
except AttributeError:
18+
TclVersion = 7.3
2119

2220
def _flatten(tuple):
2321
res = ()
@@ -347,10 +345,10 @@ def quit(self):
347345
self.tk.quit()
348346
def _getints(self, string):
349347
if not string: return None
350-
res = ()
351-
for v in self.tk.splitlist(string):
352-
res = res + (self.tk.getint(v),)
353-
return res
348+
return tuple(map(self.tk.getint, self.tk.splitlist(string)))
349+
def _getdoubles(self, string):
350+
if not string: return None
351+
return tuple(map(self.tk.getdouble, self.tk.splitlist(string)))
354352
def _getboolean(self, string):
355353
if string:
356354
return self.tk.getboolean(string)
@@ -438,29 +436,9 @@ def apply_func(self, func, args):
438436
except SystemExit, msg:
439437
raise SystemExit, msg
440438
except:
441-
try:
442-
try:
443-
t = sys.exc_traceback
444-
while t:
445-
sys.stderr.write(
446-
' %s, line %s\n' %
447-
(t.tb_frame.f_code,
448-
t.tb_lineno))
449-
t = t.tb_next
450-
finally:
451-
sys.stderr.write('%s: %s\n' %
452-
(sys.exc_type,
453-
sys.exc_value))
454-
(sys.last_type,
455-
sys.last_value,
456-
sys.last_traceback) = (sys.exc_type,
457-
sys.exc_value,
458-
sys.exc_traceback)
459-
import pdb
460-
pdb.pm()
461-
except:
462-
print '*** Error in error handling ***'
463-
print sys.exc_type, ':', sys.exc_value
439+
import traceback
440+
print "Exception in Tkinter callback"
441+
traceback.print_exc()
464442

465443
class Wm:
466444
def aspect(self,

0 commit comments

Comments
 (0)