Python tkinter.TclError() Examples
The following are 30
code examples of tkinter.TclError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tkinter
, or try the search function
.
Example #1
Source File: gui.py From Telethon with MIT License | 9 votes |
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()
Example #2
Source File: misc.py From SEM with MIT License | 7 votes |
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')
Example #3
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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']))
Example #4
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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 ''
Example #5
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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()
Example #6
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_get(self): if self.wantobjects: conv = lambda x: x else: conv = float scale_width = self.scale.winfo_width() self.assertEqual(self.scale.get(scale_width, 0), self.scale['to']) self.assertEqual(conv(self.scale.get(0, 0)), conv(self.scale['from'])) self.assertEqual(self.scale.get(), self.scale['value']) self.scale['value'] = 30 self.assertEqual(self.scale.get(), self.scale['value']) self.assertRaises(tkinter.TclError, self.scale.get, '', 0) self.assertRaises(tkinter.TclError, self.scale.get, 0, '')
Example #7
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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.assertNotEqual(curr_pos, self.paned.sashpos(0)) self.assertIsInstance(self.paned.sashpos(0), int)
Example #8
Source File: test_style.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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()
Example #10
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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()
Example #11
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
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()
Example #12
Source File: widget_tests.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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
Example #13
Source File: _backend_tk.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #14
Source File: tkagg.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #15
Source File: _backend_tk.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #16
Source File: _backend_tk.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #17
Source File: tkagg.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #18
Source File: test_style.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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'})])
Example #19
Source File: autocomplete_entrylistbox.py From ttkwidgets with GNU General Public License v3.0 | 6 votes |
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"
Example #20
Source File: autocomplete_entrylistbox.py From ttkwidgets with GNU General Public License v3.0 | 6 votes |
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"
Example #21
Source File: autocomplete_entrylistbox.py From ttkwidgets with GNU General Public License v3.0 | 5 votes |
def _update_entry(self, event=None): """Update entry when an item is selected in the listbox.""" try: sel = self.listbox.get(self.listbox.curselection()[0]) except (tk.TclError, IndexError): return self.entry.delete(0, "end") self.entry.insert(0, sel) self.entry.selection_clear() self.entry.icursor("end") self.event_generate('<<ItemSelect>>')
Example #22
Source File: autocomplete_entrylistbox.py From ttkwidgets with GNU General Public License v3.0 | 5 votes |
def configure(self, cnf={}, **kw): kwargs = {} kwargs.update(cnf) kwargs.update(kw) # completion settings self._allow_other_values = kwargs.pop('allow_other_values', self._allow_other_values) if 'completevalues' in kwargs: completevalues = kwargs.pop('completevalues') self._completevalues = completevalues self.listbox.delete(0, 'end') for c in self._completevalues: self.listbox.insert('end', c) # autohidescrollbar autohidescrollbar = isinstance(self._scrollbar, AutoHideScrollbar) autohidescrollbar2 = kwargs.pop('autohidescrollbar', autohidescrollbar) if autohidescrollbar != autohidescrollbar2: self._scrollbar.destroy() if autohidescrollbar2: self._scrollbar = AutoHideScrollbar(self, orient=tk.VERTICAL, command=self.listbox.yview) else: self._scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL, command=self.listbox.yview) self.listbox.configure(yscrollcommand=self._scrollbar.set) self._scrollbar.grid(row=1, column=1, sticky='ns') # entry/listbox settings entry_listbox_kw = {} for key in ['font', 'exportselection', 'width']: if key in kwargs: entry_listbox_kw[key] = kwargs.pop(key) self.entry.configure(entry_listbox_kw) self.listbox.configure(entry_listbox_kw) if 'justify' in kwargs: justify = kwargs.pop('justify') self.entry.configure(justify=justify) try: self.listbox.configure(justify=justify) # this is an option only for tk >= 8.6.5 except tk.TclError: pass # frame settings ttk.Frame.config(self, kwargs)
Example #23
Source File: ImageTk.py From teleport with Apache License 2.0 | 5 votes |
def _pilbitmap_check(): global _pilbitmap_ok if _pilbitmap_ok is None: try: im = Image.new("1", (1, 1)) tkinter.BitmapImage(data="PIL:%d" % im.im.id) _pilbitmap_ok = 1 except tkinter.TclError: _pilbitmap_ok = 0 return _pilbitmap_ok
Example #24
Source File: autocomplete_entrylistbox.py From ttkwidgets with GNU General Public License v3.0 | 5 votes |
def _validate(self, action, modif, pos, prev_txt, new_txt): """Complete the text in the entry with values.""" try: sel = self.entry.selection_get() txt = prev_txt.replace(sel, '') except tk.TclError: txt = prev_txt if action == "0": txt = txt[:int(pos)] + txt[int(pos) + 1:] return True else: txt = txt[:int(pos)] + modif + txt[int(pos):] l = [i for i in self._completevalues if i[:len(txt)] == txt] if l: i = self._completevalues.index(l[0]) self.listbox.selection_clear(0, "end") self.listbox.selection_set(i) self.listbox.see(i) index = self.entry.index("insert") self.entry.delete(0, "end") self.entry.insert(0, l[0].replace("\ ", " ")) self.entry.selection_range(index + 1, "end") self.entry.icursor(index + 1) return True else: return self._allow_other_values
Example #25
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_insert(self): self.assertRaises(tkinter.TclError, self.paned.insert, None, 0) self.assertRaises(tkinter.TclError, self.paned.insert, 0, None) self.assertRaises(tkinter.TclError, self.paned.insert, 0, 0) child = ttk.Label(self.root) child2 = ttk.Label(self.root) child3 = ttk.Label(self.root) self.assertRaises(tkinter.TclError, self.paned.insert, 0, child) self.paned.insert('end', child2) self.paned.insert(0, child) self.assertEqual(self.paned.panes(), (str(child), str(child2))) self.paned.insert(0, child2) self.assertEqual(self.paned.panes(), (str(child2), str(child))) self.paned.insert('end', child3) self.assertEqual(self.paned.panes(), (str(child2), str(child), str(child3))) # reinserting a child should move it to its current position panes = self.paned.panes() self.paned.insert('end', child3) self.assertEqual(panes, self.paned.panes()) # moving child3 to child2 position should result in child2 ending up # in previous child position and child ending up in previous child3 # position self.paned.insert(child2, child3) self.assertEqual(self.paned.panes(), (str(child3), str(child2), str(child)))
Example #26
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_forget(self): self.assertRaises(tkinter.TclError, self.paned.forget, None) self.assertRaises(tkinter.TclError, self.paned.forget, 0) self.paned.add(ttk.Label(self.root)) self.paned.forget(0) self.assertRaises(tkinter.TclError, self.paned.forget, 0)
Example #27
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_add(self): # attempt to add a child that is not a direct child of the paned window label = ttk.Label(self.paned) child = ttk.Label(label) self.assertRaises(tkinter.TclError, self.paned.add, child) label.destroy() child.destroy() # another attempt label = ttk.Label(self.root) child = ttk.Label(label) self.assertRaises(tkinter.TclError, self.paned.add, child) child.destroy() label.destroy() good_child = ttk.Label(self.root) self.paned.add(good_child) # re-adding a child is not accepted self.assertRaises(tkinter.TclError, self.paned.add, good_child) other_child = ttk.Label(self.paned) self.paned.add(other_child) self.assertEqual(self.paned.pane(0), self.paned.pane(1)) self.assertRaises(tkinter.TclError, self.paned.pane, 2) good_child.destroy() other_child.destroy() self.assertRaises(tkinter.TclError, self.paned.pane, 0)
Example #28
Source File: ImageTk.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _pilbitmap_check(): global _pilbitmap_ok if _pilbitmap_ok is None: try: im = Image.new("1", (1, 1)) tkinter.BitmapImage(data="PIL:%d" % im.im.id) _pilbitmap_ok = 1 except tkinter.TclError: _pilbitmap_ok = 0 return _pilbitmap_ok
Example #29
Source File: test_widgets.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_set(self): if self.wantobjects: conv = lambda x: x else: conv = float # set restricts the max/min values according to the current range max = conv(self.scale['to']) new_max = max + 10 self.scale.set(new_max) self.assertEqual(conv(self.scale.get()), max) min = conv(self.scale['from']) self.scale.set(min - 1) self.assertEqual(conv(self.scale.get()), min) # changing directly the variable doesn't impose this limitation tho var = tkinter.DoubleVar(self.root) self.scale['variable'] = var var.set(max + 5) self.assertEqual(conv(self.scale.get()), var.get()) self.assertEqual(conv(self.scale.get()), max + 5) del var # the same happens with the value option self.scale['value'] = max + 10 self.assertEqual(conv(self.scale.get()), max + 10) self.assertEqual(conv(self.scale.get()), conv(self.scale['value'])) # nevertheless, note that the max/min values we can get specifying # x, y coords are the ones according to the current range self.assertEqual(conv(self.scale.get(0, 0)), min) self.assertEqual(conv(self.scale.get(self.scale.winfo_width(), 0)), max) self.assertRaises(tkinter.TclError, self.scale.set, None)
Example #30
Source File: test_imagetk.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): try: # setup tk tk.Frame() # root = tk.Tk() except tk.TclError as v: self.skipTest("TCL Error: %s" % v)