本文整理汇总了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: main
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import TclError [as 别名]
def main(loop, interval=0.05):
client = TelegramClient(SESSION, API_ID, API_HASH, loop=loop)
try:
await client.connect()
except Exception as e:
print('Failed to connect', e, file=sys.stderr)
return
app = App(client)
try:
while True:
# We want to update the application but get back
# to asyncio's event loop. For this we sleep a
# short time so the event loop can run.
#
# https://www.reddit.com/r/Python/comments/33ecpl
app.update()
await asyncio.sleep(interval)
except KeyboardInterrupt:
pass
except tkinter.TclError as e:
if 'application has been destroyed' not in e.args[0]:
raise
finally:
await app.cl.disconnect()
示例3: get
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import TclError [as 别名]
def get(self):
try:
if self.variable:
return self.variable.get()
elif type(self.input) == tk.Text:
return self.input.get('1.0', tk.END)
else:
return self.input.get()
except (TypeError, tk.TclError):
# happens when numeric fields are empty.
return ''
示例4: _set_minimum
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import TclError [as 别名]
def _set_minimum(self, *args):
current = self.get()
try:
new_min = self.min_var.get()
self.config(from_=new_min)
except (tk.TclError, ValueError):
pass
if not current:
self.delete(0, tk.END)
else:
self.variable.set(current)
self.trigger_focusout_validation()
示例5: _set_maximum
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import TclError [as 别名]
def _set_maximum(self, *args):
current = self.get()
try:
new_max = self.max_var.get()
self.config(to=new_max)
except (tk.TclError, ValueError):
pass
if not current:
self.delete(0, tk.END)
else:
self.variable.set(current)
self.trigger_focusout_validation()
示例6: 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)
示例7: 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__()
# x1, x2, y1, y2
bboxptr = (bbox_array[0, 0], bbox_array[1, 0],
bbox_array[0, 1], bbox_array[1, 1])
else:
bboxptr = 0
data = np.asarray(aggimage)
dataptr = (data.shape[0], data.shape[1], data.ctypes.data)
try:
tk.call(
"PyAggImagePhoto", photoimage,
dataptr, colormode, bboxptr)
except tk.TclError:
if hasattr(tk, 'interpaddr'):
_tkagg.tkinit(tk.interpaddr(), 1)
else:
# very old python?
_tkagg.tkinit(tk, 0)
tk.call("PyAggImagePhoto", photoimage,
dataptr, colormode, bboxptr)
示例8: _up
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import TclError [as 别名]
def _up(self, event):
"""Navigate in the listbox with up key."""
try:
i = self.listbox.curselection()[0]
self.listbox.selection_clear(0, "end")
if i <= 0:
i = len(self._completevalues)
self.listbox.see(i - 1)
self.listbox.select_set(i - 1)
self.listbox.activate(i - 1)
except (tk.TclError, IndexError):
self.listbox.selection_clear(0, "end")
i = len(self._completevalues)
self.listbox.see(i - 1)
self.listbox.select_set(i - 1)
self.listbox.activate(i - 1)
self.listbox.event_generate('<<ListboxSelect>>')
return "break"
示例9: _down
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import TclError [as 别名]
def _down(self, event):
"""Navigate in the listbox with down key."""
try:
i = self.listbox.curselection()[0]
self.listbox.selection_clear(0, "end")
if i >= len(self._completevalues) - 1:
i = -1
self.listbox.see(i + 1)
self.listbox.select_set(i + 1)
self.listbox.activate(i + 1)
except (tk.TclError, IndexError):
self.listbox.selection_clear(0, "end")
self.listbox.see(0)
self.listbox.select_set(0)
self.listbox.activate(0)
self.listbox.event_generate('<<ListboxSelect>>')
return "break"
示例10: 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)
示例11: 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__()
# x1, x2, y1, y2
bboxptr = (bbox_array[0, 0], bbox_array[1, 0],
bbox_array[0, 1], bbox_array[1, 1])
else:
bboxptr = 0
data = np.asarray(aggimage)
dataptr = (data.shape[0], data.shape[1], data.ctypes.data)
try:
tk.call(
"PyAggImagePhoto", photoimage,
dataptr, colormode, bboxptr)
except Tk.TclError:
if hasattr(tk, 'interpaddr'):
_tkagg.tkinit(tk.interpaddr(), 1)
else:
# very old python?
_tkagg.tkinit(tk, 0)
tk.call("PyAggImagePhoto", photoimage,
dataptr, colormode, bboxptr)
示例12: 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
示例13: 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'})])
示例14: 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)
示例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']))