Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Don't skip parts of a tutorial because you don't know the problem domain - you don't need to know how to play cards to understand how card game code relates to what the program <em>does</em>. To your actual problem:</p> <pre><code>class Application(**Frame**): </code></pre> <p>This creates a class <code>Application</code> that inherits from a class <code>Frame</code>. If you don't know inheritance, the tutorial you're following should explain it, or you could try this <a href="http://www.jesshamrick.com/2011/05/18/an-introduction-to-classes-and-inheritance-in-python/" rel="nofollow">introduction to classes and inheritance</a> that I just googled up.</p> <pre><code>**def __init__(self, master): </code></pre> <p>This creates a method, with the name <code>__init__</code>. This is a special method in Python, which behaves similarly to a constructor in other languages - essentially, whenever an <code>Application</code> is created, Python will immediately call its <code>__init__</code> method before it gives the new object back to whoever made it. <code>master</code> is just an argument, same as any other to any other function.</p> <pre><code>super(Application, self).__init__(master) </code></pre> <p>This calls the constructor of the superclass, to let it initialise the new object. <code>super(Application, self)</code> figures out what the superclass <em>is</em> (in this case it is <code>Frame</code>; in more complex cases that you will come to eventually, this is harder to work out and <code>super</code>'s magic becomes important).</p> <pre><code>self.create_widgets()** </code></pre> <p>This calls the method <code>create_widgets</code>, which you define below this. The object before the <code>.</code> gets passed into the method as the first argument, <code>self</code> - so, this calls a different method on the same object that the method you're in has been called on.</p> <pre><code>app = Application(root) </code></pre> <p>This creates an <code>Application</code> - objects are created by calling the class, like how <code>list()</code> creates a list. The argument you pass in gets handed to <code>__init__</code> as its second argument (the new <code>Application</code> that Python creates behind the scenes gets passed as the first argument, <code>self</code>, as above). Python creates a new <code>Application</code>, calls its <code>__init__</code> for you, and then assigns the new object to the name 'app'.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload