May 2018
Beginner to intermediate
452 pages
11h 26m
English
ValidatedSpinbox is one of the more complicated widgets we created for our application, so it's a good place to start writing tests.
Subclass the TkTestCase class to create a test case for ValidatedSpinbox as follows:
class TestValidatedSpinbox(TkTestCase):
def setUp(self):
self.value = tk.DoubleVar()
self.vsb = widgets.ValidatedSpinbox(
self.root,
textvariable=self.value,
from_=-10, to=10, increment=1)
self.vsb.pack()
self.vsb.wait_visibility()
def tearDown(self):
self.vsb.destroy()
Our setup method creates a variable in which to store the widget's value, then creates an instance of the ValidatedSpinbox widget with some basic settings: a minimum value of -10, a maximum of 10, and an increment of ...