本文整理汇总了Python中Tkinter.TclError方法的典型用法代码示例。如果您正苦于以下问题:Python Tkinter.TclError方法的具体用法?Python Tkinter.TclError怎么用?Python Tkinter.TclError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter
的用法示例。
在下文中一共展示了Tkinter.TclError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_all
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def add_all(self, event):
if self.frame.current_selection is not None:
start = self.frame.charindex2position(self.frame.current_selection.lb)
end = self.frame.charindex2position(self.frame.current_selection.ub)
else:
start, end = ("sel.first", "sel.last")
try:
target = re.escape(self.frame.text.get(start, end).strip())
pattern = (u"\\b" if target[0].isalnum() else u"((?<=\\s)|(?<=^))") + target + (u"\\b" if target[-1].isalnum() else u"(?=\\s|$)")
regex = re.compile(pattern, re.U + re.M)
for match in regex.finditer(self.frame.doc.content):
cur_start, cur_end = self.frame.charindex2position(match.start()), self.frame.charindex2position(match.end())
if Tag(self.type, match.start(), match.end()) not in self.frame.current_annotations:
self.frame.wish_to_add = [self.type, cur_start, cur_end]
self.frame.add_annotation(None, remove_focus=False)
except tkinter.TclError:
raise
self.frame.type_combos[self.level].current(0)
self.frame.wish_to_add = None
self.frame.current_selection = None
self.frame.current_type_hierarchy_level = 0
self.frame.update_level()
self.frame.text.tag_remove("BOLD", "1.0", 'end')
示例2: test_layout
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_layout(self):
style = self.style
self.assertRaises(Tkinter.TclError, style.layout, 'NotALayout')
tv_style = style.layout('Treeview')
# "erase" Treeview layout
style.layout('Treeview', '')
self.assertEqual(style.layout('Treeview'),
[('null', {'sticky': 'nswe'})]
)
# restore layout
style.layout('Treeview', tv_style)
self.assertEqual(style.layout('Treeview'), tv_style)
# should return a list
self.assertTrue(isinstance(style.layout('TButton'), list))
# correct layout, but "option" doesn't exist as option
self.assertRaises(Tkinter.TclError, style.layout, 'Treeview',
[('name', {'option': 'inexistent'})])
示例3: test_theme_use
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_theme_use(self):
self.assertRaises(Tkinter.TclError, self.style.theme_use,
'nonexistingname')
curr_theme = self.style.theme_use()
new_theme = None
for theme in self.style.theme_names():
if theme != curr_theme:
new_theme = theme
self.style.theme_use(theme)
break
else:
# just one theme available, can't go on with tests
return
self.assertFalse(curr_theme == new_theme)
self.assertFalse(new_theme != self.style.theme_use())
self.style.theme_use(curr_theme)
示例4: test_invoke
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_invoke(self):
success = []
def cb_test():
success.append(1)
return "cb test called"
cbtn = ttk.Checkbutton(command=cb_test)
# the variable automatically created by ttk.Checkbutton is actually
# undefined till we invoke the Checkbutton
self.assertEqual(cbtn.state(), ('alternate', ))
self.assertRaises(Tkinter.TclError, cbtn.tk.globalgetvar,
cbtn['variable'])
res = cbtn.invoke()
self.assertEqual(res, "cb test called")
self.assertEqual(cbtn['onvalue'],
cbtn.tk.globalgetvar(cbtn['variable']))
self.assertTrue(success)
cbtn['command'] = ''
res = cbtn.invoke()
self.assertEqual(res, '')
self.assertFalse(len(success) > 1)
self.assertEqual(cbtn['offvalue'],
cbtn.tk.globalgetvar(cbtn['variable']))
示例5: test_sashpos
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_sashpos(self):
self.assertRaises(Tkinter.TclError, self.paned.sashpos, None)
self.assertRaises(Tkinter.TclError, self.paned.sashpos, '')
self.assertRaises(Tkinter.TclError, self.paned.sashpos, 0)
child = ttk.Label(self.paned, text='a')
self.paned.add(child, weight=1)
self.assertRaises(Tkinter.TclError, self.paned.sashpos, 0)
child2 = ttk.Label(self.paned, text='b')
self.paned.add(child2)
self.assertRaises(Tkinter.TclError, self.paned.sashpos, 1)
self.paned.pack(expand=True, fill='both')
self.paned.wait_visibility()
curr_pos = self.paned.sashpos(0)
self.paned.sashpos(0, 1000)
self.assertTrue(curr_pos != self.paned.sashpos(0))
self.assertTrue(isinstance(self.paned.sashpos(0), int))
示例6: test_column
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_column(self):
# return a dict with all options/values
self.assertTrue(isinstance(self.tv.column('#0'), dict))
# return a single value of the given option
self.assertTrue(isinstance(self.tv.column('#0', width=None), int))
# set a new value for an option
self.tv.column('#0', width=10)
# testing new way to get option value
self.assertEqual(self.tv.column('#0', 'width'), 10)
self.assertEqual(self.tv.column('#0', width=None), 10)
# check read-only option
self.assertRaises(Tkinter.TclError, self.tv.column, '#0', id='X')
self.assertRaises(Tkinter.TclError, self.tv.column, 'invalid')
invalid_kws = [
{'unknown_option': 'some value'}, {'stretch': 'wrong'},
{'anchor': 'wrong'}, {'width': 'wrong'}, {'minwidth': 'wrong'}
]
for kw in invalid_kws:
self.assertRaises(Tkinter.TclError, self.tv.column, '#0',
**kw)
示例7: test_delete
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_delete(self):
self.assertRaises(Tkinter.TclError, self.tv.delete, '#0')
item_id = self.tv.insert('', 'end')
item2 = self.tv.insert(item_id, 'end')
self.assertEqual(self.tv.get_children(), (item_id, ))
self.assertEqual(self.tv.get_children(item_id), (item2, ))
self.tv.delete(item_id)
self.assertFalse(self.tv.get_children())
# reattach should fail
self.assertRaises(Tkinter.TclError,
self.tv.reattach, item_id, '', 'end')
# test multiple item delete
item1 = self.tv.insert('', 'end')
item2 = self.tv.insert('', 'end')
self.assertEqual(self.tv.get_children(), (item1, item2))
self.tv.delete(item1, item2)
self.assertFalse(self.tv.get_children())
示例8: test_heading
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_heading(self):
# check a dict is returned
self.assertTrue(isinstance(self.tv.heading('#0'), dict))
# check a value is returned
self.tv.heading('#0', text='hi')
self.assertEqual(self.tv.heading('#0', 'text'), 'hi')
self.assertEqual(self.tv.heading('#0', text=None), 'hi')
# invalid option
self.assertRaises(Tkinter.TclError, self.tv.heading, '#0',
background=None)
# invalid value
self.assertRaises(Tkinter.TclError, self.tv.heading, '#0',
anchor=1)
# XXX skipping for now; should be fixed to work with newer ttk
示例9: testLoadTkFailure
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def testLoadTkFailure(self):
old_display = None
if sys.platform.startswith(('win', 'darwin', 'cygwin')):
# no failure possible on windows?
# XXX Maybe on tk older than 8.4.13 it would be possible,
# see tkinter.h.
return
with test_support.EnvironmentVarGuard() as env:
if 'DISPLAY' in os.environ:
del env['DISPLAY']
# on some platforms, deleting environment variables
# doesn't actually carry through to the process level
# because they don't support unsetenv
# If that's the case, abort.
display = os.popen('echo $DISPLAY').read().strip()
if display:
return
tcl = Tcl()
self.assertRaises(TclError, tcl.winfo_geometry)
self.assertRaises(TclError, tcl.loadtk)
示例10: test_search
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_search(self):
text = self.text
# pattern and index are obligatory arguments.
self.assertRaises(Tkinter.TclError, text.search, None, '1.0')
self.assertRaises(Tkinter.TclError, text.search, 'a', None)
self.assertRaises(Tkinter.TclError, text.search, None, None)
# Invalid text index.
self.assertRaises(Tkinter.TclError, text.search, '', 0)
# Check if we are getting the indices as strings -- you are likely
# to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it.
text.insert('1.0', 'hi-test')
self.assertEqual(text.search('-test', '1.0', 'end'), '1.2')
self.assertEqual(text.search('test', '1.0', 'end'), '1.3')
示例11: showtip
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def showtip(self, text):
"Display text in tooltip window"
self.text = text
if self.tipwindow or not self.text:
return
x, y, _, _ = self.widget.bbox("insert")
x = x + self.widget.winfo_rootx() + 27
y = y + self.widget.winfo_rooty()
self.tipwindow = tw = Tk.Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x, y))
try:
# For Mac OS
tw.tk.call("::tk::unsupported::MacWindowStyle",
"style", tw._w,
"help", "noActivates")
except Tk.TclError:
pass
label = Tk.Label(tw, text=self.text, justify=Tk.LEFT,
background="#ffffe0", relief=Tk.SOLID, borderwidth=1,
)
label.pack(ipadx=1)
示例12: blit
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def blit(photoimage, aggimage, bbox=None, colormode=1):
tk = photoimage.tk
if bbox is not None:
bbox_array = bbox.__array__()
else:
bbox_array = None
try:
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
except Tk.TclError:
try:
try:
_tkagg.tkinit(tk.interpaddr(), 1)
except AttributeError:
_tkagg.tkinit(id(tk), 0)
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox_array))
except (ImportError, AttributeError, Tk.TclError):
raise
示例13: checkInvalidParam
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def checkInvalidParam(self, widget, name, value, errmsg=None,
keep_orig=True):
orig = widget[name]
if errmsg is not None:
errmsg = errmsg.format(value)
with self.assertRaises(tkinter.TclError) as cm:
widget[name] = value
if errmsg is not None:
self.assertEqual(str(cm.exception), errmsg)
if keep_orig:
self.assertEqual(widget[name], orig)
else:
widget[name] = orig
with self.assertRaises(tkinter.TclError) as cm:
widget.configure({name: value})
if errmsg is not None:
self.assertEqual(str(cm.exception), errmsg)
if keep_orig:
self.assertEqual(widget[name], orig)
else:
widget[name] = orig
示例14: test_layout
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_layout(self):
style = self.style
self.assertRaises(tkinter.TclError, style.layout, 'NotALayout')
tv_style = style.layout('Treeview')
# "erase" Treeview layout
style.layout('Treeview', '')
self.assertEqual(style.layout('Treeview'),
[('null', {'sticky': 'nswe'})]
)
# restore layout
style.layout('Treeview', tv_style)
self.assertEqual(style.layout('Treeview'), tv_style)
# should return a list
self.assertIsInstance(style.layout('TButton'), list)
# correct layout, but "option" doesn't exist as option
self.assertRaises(tkinter.TclError, style.layout, 'Treeview',
[('name', {'option': 'inexistent'})])
示例15: test_invoke
# 需要导入模块: import Tkinter [as 别名]
# 或者: from Tkinter import TclError [as 别名]
def test_invoke(self):
success = []
def cb_test():
success.append(1)
return "cb test called"
cbtn = ttk.Checkbutton(self.root, command=cb_test)
# the variable automatically created by ttk.Checkbutton is actually
# undefined till we invoke the Checkbutton
self.assertEqual(cbtn.state(), ('alternate', ))
self.assertRaises(tkinter.TclError, cbtn.tk.globalgetvar,
cbtn['variable'])
res = cbtn.invoke()
self.assertEqual(res, "cb test called")
self.assertEqual(cbtn['onvalue'],
cbtn.tk.globalgetvar(cbtn['variable']))
self.assertTrue(success)
cbtn['command'] = ''
res = cbtn.invoke()
self.assertFalse(str(res))
self.assertLessEqual(len(success), 1)
self.assertEqual(cbtn['offvalue'],
cbtn.tk.globalgetvar(cbtn['variable']))