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


Python Tcl.createcommand方法代码示例

本文整理汇总了Python中tkinter.Tcl.createcommand方法的典型用法代码示例。如果您正苦于以下问题:Python Tcl.createcommand方法的具体用法?Python Tcl.createcommand怎么用?Python Tcl.createcommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.Tcl的用法示例。


在下文中一共展示了Tcl.createcommand方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TclTest

# 需要导入模块: from tkinter import Tcl [as 别名]
# 或者: from tkinter.Tcl import createcommand [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(passValue('str\x00ing'), 'str\x00ing')
        self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd')
        self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac')
        self.assertEqual(passValue(b'str\x00ing'), 'str\x00ing')
        self.assertEqual(passValue(b'str\xc0\x80ing'), 'str\x00ing')
        for i in (0, 1, -1, 2**31-1, -2**31):
            self.assertEqual(passValue(i), i if self.wantobjects else str(i))
        for f in (0.0, 1.0, -1.0, 1/3,
                  sys.float_info.min, sys.float_info.max,
                  -sys.float_info.min, -sys.float_info.max):
            if self.wantobjects:
                self.assertEqual(passValue(f), f)
            else:
                self.assertEqual(float(passValue(f)), f)
        if self.wantobjects:
            f = passValue(float('nan'))
            self.assertNotEqual(f, f)
            self.assertEqual(passValue(float('inf')), float('inf'))
            self.assertEqual(passValue(-float('inf')), -float('inf'))
        else:
            f = float(passValue(float('nan')))
            self.assertNotEqual(f, f)
            self.assertEqual(float(passValue(float('inf'))), float('inf'))
            self.assertEqual(float(passValue(-float('inf'))), -float('inf'))
        self.assertEqual(passValue((1, '2', (3.4,))),
                         (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')

    def test_user_command(self):
        result = None
        def testfunc(arg):
            nonlocal result
            result = arg
            return arg
        self.interp.createcommand('testfunc', testfunc)
        self.addCleanup(self.interp.tk.deletecommand, 'testfunc')
        def check(value, expected, eq=self.assertEqual):
            r = self.interp.call('testfunc', value)
            self.assertIsInstance(result, str)
            eq(result, expected)
            self.assertIsInstance(r, str)
            eq(r, expected)
        def float_eq(actual, expected):
            expected = float(expected)
            self.assertAlmostEqual(float(actual), expected,
                                   delta=abs(expected) * 1e-10)
        def nan_eq(actual, expected):
            actual = float(actual)
            self.assertNotEqual(actual, actual)

        check(True, '1')
        check(False, '0')
        check('string', 'string')
        check('string\xbd', 'string\xbd')
        check('string\u20ac', 'string\u20ac')
        check(b'string', 'string')
        check(b'string\xe2\x82\xac', 'string\u20ac')
        check('str\x00ing', 'str\x00ing')
        check('str\x00ing\xbd', 'str\x00ing\xbd')
        check('str\x00ing\u20ac', 'str\x00ing\u20ac')
        check(b'str\xc0\x80ing', 'str\x00ing')
        check(b'str\xc0\x80ing\xe2\x82\xac', 'str\x00ing\u20ac')
        for i in (0, 1, -1, 2**31-1, -2**31):
            check(i, str(i))
        for f in (0.0, 1.0, -1.0):
            check(f, repr(f))
        for f in (1/3.0, sys.float_info.min, sys.float_info.max,
开发者ID:IgnusIndia,项目名称:pythonexperiment,代码行数:70,代码来源:test_tcl.py

示例2: TclTest

# 需要导入模块: from tkinter import Tcl [as 别名]
# 或者: from tkinter.Tcl import createcommand [as 别名]

#.........这里部分代码省略.........
            0.0,
            1.0,
            -1.0,
            1 / 3,
            sys.float_info.min,
            sys.float_info.max,
            -sys.float_info.min,
            -sys.float_info.max,
        ):
            if self.wantobjects:
                self.assertEqual(passValue(f), f)
            else:
                self.assertEqual(float(passValue(f)), f)
        if self.wantobjects:
            f = passValue(float("nan"))
            self.assertNotEqual(f, f)
            self.assertEqual(passValue(float("inf")), float("inf"))
            self.assertEqual(passValue(-float("inf")), -float("inf"))
        else:
            f = float(passValue(float("nan")))
            self.assertNotEqual(f, f)
            self.assertEqual(float(passValue(float("inf"))), float("inf"))
            self.assertEqual(float(passValue(-float("inf"))), -float("inf"))
        self.assertEqual(passValue((1, "2", (3.4,))), (1, "2", (3.4,)) if self.wantobjects else "1 2 3.4")

    def test_user_command(self):
        result = None

        def testfunc(arg):
            nonlocal result
            result = arg
            return arg

        self.interp.createcommand("testfunc", testfunc)

        def check(value, expected, eq=self.assertEqual):
            r = self.interp.call("testfunc", value)
            self.assertIsInstance(result, str)
            eq(result, expected)
            self.assertIsInstance(r, str)
            eq(r, expected)

        def float_eq(actual, expected):
            expected = float(expected)
            self.assertAlmostEqual(float(actual), expected, delta=abs(expected) * 1e-10)

        def nan_eq(actual, expected):
            actual = float(actual)
            self.assertNotEqual(actual, actual)

        check(True, "1")
        check(False, "0")
        check("string", "string")
        check("string\xbd", "string\xbd")
        check("string\u20ac", "string\u20ac")
        check(b"string", "string")
        check(b"string\xe2\x82\xac", "string\u20ac")
        check("str\x00ing", "str\x00ing")
        check("str\x00ing\xbd", "str\x00ing\xbd")
        check("str\x00ing\u20ac", "str\x00ing\u20ac")
        check(b"str\xc0\x80ing", "str\x00ing")
        check(b"str\xc0\x80ing\xe2\x82\xac", "str\x00ing\u20ac")
        for i in (0, 1, -1, 2 ** 31 - 1, -2 ** 31):
            check(i, str(i))
        for f in (0.0, 1.0, -1.0):
            check(f, repr(f))
开发者ID:TheYear2015,项目名称:TextWorldEditor,代码行数:70,代码来源:test_tcl.py

示例3: TclTest

# 需要导入模块: from tkinter import Tcl [as 别名]
# 或者: from tkinter.Tcl import createcommand [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(passValue(b'str\xbding'),
                         b'str\xbding' if self.wantobjects else 'str\xbding')
        for i in self.get_integers():
            self.assertEqual(passValue(i), i if self.wantobjects else str(i))
        if tcl_version < (8, 5):  # bignum was added in Tcl 8.5
            self.assertEqual(passValue(2**1000), str(2**1000))
        for f in (0.0, 1.0, -1.0, 1/3,
                  sys.float_info.min, sys.float_info.max,
                  -sys.float_info.min, -sys.float_info.max):
            if self.wantobjects:
                self.assertEqual(passValue(f), f)
            else:
                self.assertEqual(float(passValue(f)), f)
        if self.wantobjects:
            f = passValue(float('nan'))
            self.assertNotEqual(f, f)
            self.assertEqual(passValue(float('inf')), float('inf'))
            self.assertEqual(passValue(-float('inf')), -float('inf'))
        else:
            self.assertEqual(float(passValue(float('inf'))), float('inf'))
            self.assertEqual(float(passValue(-float('inf'))), -float('inf'))
            # XXX NaN representation can be not parsable by float()
        self.assertEqual(passValue((1, '2', (3.4,))),
                         (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
        self.assertEqual(passValue(['a', ['b', 'c']]),
                         ('a', ('b', 'c')) if self.wantobjects else 'a {b c}')

    def test_user_command(self):
        result = None
        def testfunc(arg):
            nonlocal result
            result = arg
            return arg
        self.interp.createcommand('testfunc', testfunc)
        self.addCleanup(self.interp.tk.deletecommand, 'testfunc')
        def check(value, expected=None, *, eq=self.assertEqual):
            if expected is None:
                expected = value
            nonlocal result
            result = None
            r = self.interp.call('testfunc', value)
            self.assertIsInstance(result, str)
            eq(result, expected)
            self.assertIsInstance(r, str)
            eq(r, expected)
        def float_eq(actual, expected):
            self.assertAlmostEqual(float(actual), expected,
                                   delta=abs(expected) * 1e-10)

        check(True, '1')
        check(False, '0')
        check('string')
        check('string\xbd')
        check('string\u20ac')
        check('')
        check(b'string', 'string')
        check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
        check(b'string\xbd', 'string\xbd')
        check(b'', '')
        check('str\x00ing')
        check('str\x00ing\xbd')
        check('str\x00ing\u20ac')
        check(b'str\x00ing', 'str\x00ing')
        check(b'str\xc0\x80ing', 'str\xc0\x80ing')
        check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac')
        for i in self.get_integers():
开发者ID:ARK4579,项目名称:cpython,代码行数:70,代码来源:test_tcl.py

示例4: TclTest

# 需要导入模块: from tkinter import Tcl [as 别名]
# 或者: from tkinter.Tcl import createcommand [as 别名]

#.........这里部分代码省略.........

        self.assertEqual(passValue(True), True if self.wantobjects else '1')
        self.assertEqual(passValue(False), False if self.wantobjects else '0')
        self.assertEqual(passValue('string'), 'string')
        self.assertEqual(passValue('string\u20ac'), 'string\u20ac')
        for i in (0, 1, -1, 2**31-1, -2**31):
            self.assertEqual(passValue(i), i if self.wantobjects else str(i))
        for f in (0.0, 1.0, -1.0, 1/3,
                  sys.float_info.min, sys.float_info.max,
                  -sys.float_info.min, -sys.float_info.max):
            if self.wantobjects:
                self.assertEqual(passValue(f), f)
            else:
                self.assertEqual(float(passValue(f)), f)
        if self.wantobjects:
            f = passValue(float('nan'))
            self.assertNotEqual(f, f)
            self.assertEqual(passValue(float('inf')), float('inf'))
            self.assertEqual(passValue(-float('inf')), -float('inf'))
        else:
            f = float(passValue(float('nan')))
            self.assertNotEqual(f, f)
            self.assertEqual(float(passValue(float('inf'))), float('inf'))
            self.assertEqual(float(passValue(-float('inf'))), -float('inf'))
        self.assertEqual(passValue((1, '2', (3.4,))),
                         (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')

    def test_user_command(self):
        result = None
        def testfunc(arg):
            nonlocal result
            result = arg
            return arg
        self.interp.createcommand('testfunc', testfunc)
        def check(value, expected, eq=self.assertEqual):
            r = self.interp.call('testfunc', value)
            self.assertIsInstance(result, str)
            eq(result, expected)
            self.assertIsInstance(r, str)
            eq(r, expected)
        def float_eq(actual, expected):
            expected = float(expected)
            self.assertAlmostEqual(float(actual), expected,
                                   delta=abs(expected) * 1e-10)
        def nan_eq(actual, expected):
            actual = float(actual)
            self.assertNotEqual(actual, actual)

        check(True, '1')
        check(False, '0')
        check('string', 'string')
        check('string\xbd', 'string\xbd')
        check('string\u20ac', 'string\u20ac')
        for i in (0, 1, -1, 2**31-1, -2**31):
            check(i, str(i))
        for f in (0.0, 1.0, -1.0):
            check(f, repr(f))
        for f in (1/3.0, sys.float_info.min, sys.float_info.max,
                  -sys.float_info.min, -sys.float_info.max):
            check(f, f, eq=float_eq)
        check(float('inf'), 'Inf', eq=float_eq)
        check(-float('inf'), '-Inf', eq=float_eq)
        check(float('nan'), 'NaN', eq=nan_eq)
        check((), '')
        check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}')
开发者ID:pykomke,项目名称:Kurz_Python_KE,代码行数:69,代码来源:test_tcl.py


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