13 SEP 2019

At the class level, variables are referred to as class variables (static data), whereas variables at the instance level are called instance variables. When we expect variables are going to be consistent across instances, or when we would like to initialize a variable, we can define that variable at the class level. When we anticipate the variables will change significantly across instances, we can define them at the instance level. Defined outside of all the methods, class variables are, by convention, typically placed right below the class header and before the constructor method and other methods.

class_var.PNG

staticmethod (@staticmethod) is a method that knows nothing about the class or instance it was called on. It just gets the arguments that were passed, no implicit first argument. 

classmethod (@classmethod), is a method that gets passed the class it was called on, or the class of the instance it was called on, as first argument. This is useful when you want the method to be a factory for the class: since it gets the actual class it was called on as first argument, you can always instantiate the right class, even when subclasses are involved. Class methods are also used as an alternative constructors- for example from_string which creates as instance of the class from a string variable

TKinter: is the Python GUI toolkit. Tkinter is included with standard Linux, Microsoft Windows and Mac OS X installs of Python.

tkinter_code.PNG

tkinter.PNG

More topics covered:

  • static data
  • static – without self
  • static – fromlist
  • TKinter fonts
  • TKinter button styles
  • TKinter Implement a window class
  • mainloop – blocking method

Links:

Leave a comment