當前位置: 首頁>>代碼示例>>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: 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'})]) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:23,代碼來源:test_style.py

示例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) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:21,代碼來源:test_style.py

示例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'])) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:27,代碼來源:test_widgets.py

示例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)) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:21,代碼來源:test_widgets.py

示例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) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:23,代碼來源:test_widgets.py

示例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()) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:24,代碼來源:test_widgets.py

示例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 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:19,代碼來源:test_widgets.py

示例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) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:24,代碼來源:test_loadtk.py

示例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') 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:18,代碼來源:test_text.py

示例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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:24,代碼來源:backend_tkagg.py

示例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 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:tkagg.py

示例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 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:23,代碼來源:widget_tests.py

示例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'})]) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:23,代碼來源: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:aliyun,項目名稱:oss-ftp,代碼行數:27,代碼來源:test_widgets.py


注:本文中的Tkinter.TclError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。