当前位置: 首页>>代码示例>>Python>>正文


Python tkinter.TclError方法代码示例

本文整理汇总了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') 
开发者ID:YoannDupont,项目名称:SEM,代码行数:25,代码来源:misc.py

示例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() 
开发者ID:LonamiWebs,项目名称:Telethon,代码行数:27,代码来源:gui.py

示例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 '' 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:13,代码来源:widgets.py

示例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() 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:14,代码来源:widgets.py

示例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() 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:14,代码来源:widgets.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:23,代码来源:_backend_tk.py

示例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) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:26,代码来源:tkagg.py

示例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" 
开发者ID:TkinterEP,项目名称:ttkwidgets,代码行数:20,代码来源:autocomplete_entrylistbox.py

示例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" 
开发者ID:TkinterEP,项目名称:ttkwidgets,代码行数:19,代码来源:autocomplete_entrylistbox.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:_backend_tk.py

示例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) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:26,代码来源:tkagg.py

示例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 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:widget_tests.py

示例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'})]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_style.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_style.py

示例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'])) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_widgets.py


注:本文中的tkinter.TclError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。