O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Instances

An instance is one particular implementation of a class. Each separate instance of the same class can be completely independent from the others, or they can share attributes if the need arises.

Python uses a method called __init__ in order to initialize each instance of a class. This method can be used to set initial variables which differ between instances.

The easiest way to wrap your head around using classes is to see an example:

class Dog:    def __init__(self, name):        self.name = name    def speak(self):        print("Woof! My name is", self.name)

This code gives us a class called Dog. The _init_ function of Dog takes two arguments: self and name.

The methods of a class require the first argument to be self in order to give them access ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required