Пример #1
0
    def test_dateentry_get_set(self):
        widget = DateEntry(self.window,
                           width=12,
                           background='darkblue',
                           foreground='white',
                           borderwidth=2,
                           font='Arial 9')
        widget.pack()
        self.window.update()

        keys = [
            'exportselection', 'invalidcommand', 'justify', 'show', 'cursor',
            'style', 'state', 'takefocus', 'textvariable', 'validate',
            'validatecommand', 'width', 'xscrollcommand'
        ]
        keys.extend(widget._calendar.keys())
        self.assertEqual(sorted(list(set(keys))), sorted(widget.keys()))

        self.assertEqual(widget["background"], 'darkblue')
        self.assertEqual(widget.cget("width"), 12)

        widget["borderwidth"] = 5
        self.window.update()
        self.assertEqual(widget["borderwidth"], 5)

        widget.config(font="Arial 20 bold")
        self.window.update()
        self.assertEqual(widget["font"], "Arial 20 bold")

        widget.config(style="my.TEntry")
        self.window.update()
        self.assertEqual(widget["style"], "my.TEntry")
Пример #2
0
    def test_dateentry_get_set(self):
        widget = DateEntry(self.window, width=12, background='darkblue',
                           locale='en_US', foreground='white', borderwidth=2,
                           font='Arial 9', year=2019, month=7, day=3)
        widget.pack()
        self.window.update()

        keys = ['exportselection',
                'invalidcommand',
                'justify',
                'show',
                'cursor',
                'calendar_cursor',
                'style',
                'state',
                'takefocus',
                'textvariable',
                'validate',
                'validatecommand',
                'width',
                'xscrollcommand']
        keys.extend(widget._calendar.keys())
        self.assertEqual(sorted(list(set(keys))), sorted(widget.keys()))

        self.assertEqual(widget["background"], 'darkblue')
        self.assertEqual(widget.cget("width"), 12)

        widget["borderwidth"] = 5
        self.window.update()
        self.assertEqual(widget["borderwidth"], 5)

        widget.configure({'foreground': 'cyan', 'font': 'FreeMono 10',
                          'background': 'green'},
                         background="blue", borderwidth=4,
                         font="Arial 20 bold", justify='center')
        self.window.update()
        self.assertEqual(widget["foreground"], "cyan")
        self.assertEqual(widget["background"], "blue")
        self.assertEqual(widget["borderwidth"], 4)
        self.assertEqual(widget["font"], "Arial 20 bold")
        self.assertEqual(widget["justify"], "center")

        widget.config(font="Arial 20 bold")
        self.window.update()
        self.assertEqual(widget["font"], "Arial 20 bold")

        widget.config(style="my.TEntry")
        self.window.update()
        self.assertEqual(widget["style"], "my.TEntry")

        style = ttk.Style(self.window)
        style.theme_use('clam')

        self.assertEqual(widget["locale"], "en_US")
        self.assertEqual(widget.get(), '7/3/19')
        widget.config(locale="fr_FR")
        self.window.update()
        self.assertEqual(widget["locale"], "fr_FR")
        self.assertEqual(widget.get(), '03/07/2019')