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: 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 #4
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 #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: 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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
Source File: annotation_gui.py From SEM with MIT License | 5 votes |
def handle_char(self, event): if self.adder is None: return if not self.adder.current_annotation: try: self.text.index("sel.first") except tkinter.TclError: return the_type = self.adder.type_from_letter(event.keysym) the_type = the_type or self.adder.type_from_letter(event.keysym.lower()) if the_type is None: return if event.keysym.islower(): fst = (self.charindex2position(self.adder.current_annotation.lb) if self.adder.current_annotation else self.text.index("sel.first")) lst = (self.charindex2position(self.adder.current_annotation.ub) if self.adder.current_annotation else self.text.index("sel.last")) self.wish_to_add = [self.adder.type_from_letter(event.keysym), fst, lst] self.add_annotation(event, remove_focus=False) else: if self.adder.current_annotation is not None: start = self.charindex2position(self.adder.current_annotation.lb) end = self.charindex2position(self.adder.current_annotation.ub) else: start, end = ("sel.first", "sel.last") try: for match in find_occurrences(self.text.get(start, end), self.doc.content, whole_word=self.whole_word): cur_start, cur_end = self.charindex2position(match.start()), self.charindex2position(match.end()) if Tag(the_type, match.start(), match.end()) not in self.current_annotations: self.wish_to_add = [the_type, cur_start, cur_end] self.add_annotation(None, remove_focus=False) except tkinter.TclError: raise self.unselect()
Example #22
Source File: overviewSettings.py From PyEveLiveDPS with GNU General Public License v3.0 | 5 votes |
def _animate(self): try: self.gif = tk.PhotoImage(file=self.gif_file, format='gif -index {}'.format(self._num)) # Looping through the frames self.configure(image=self.gif) self._num += 1 except tk.TclError: # When we try a frame that doesn't exist, we know we have to start over from zero self._num = 0 if not self.stop: # If the stop flag is set, we don't repeat self.root.after(int(self.delay*1000), self._animate)
Example #23
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 #24
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 #25
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 #26
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 #27
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 #28
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 #29
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 #30
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 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 ''