Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could add an attribute to the class that you're working like this:</p> <pre><code>self.isDisarmed = False </code></pre> <p>Then add this line to <code>bomb_disarmed</code>:</p> <pre><code>self.isDisarmed = True </code></pre> <p>Then in <code>explode_first</code>, add a test to see if the bomb has been disarmed:</p> <pre><code>def explode_first(self): if self.bomb: if self.isDisarmed: self.parent.after(125, self.explode_fourth) # If bomb is disarmed, skip to the last step, where the bomb is deleted. else: # Otherwise, carry on with bomb explosion self.b1 -= 5 self.b2 -= 5 self.b3 += 5 self.b4 += 5 self.canvas.delete(self.bomb) self.bomb = self.canvas.create_oval(self.b1, self.b2, self.b3, self.b4, fill = "orange") self.parent.after(125, self.explode_second) </code></pre> <p>As a general principle, I would recommend making <code>Bomb</code> a class, which has its own internal attributes and methods. That will make it easier to keep track of what is happening to the bomb, and what the result should be, and it will make it possible to do things like have multiple bombs.</p> <p>EDIT:</p> <p>Re: drawing on an <code>App</code>'s canvas from another class's method, here's one way:</p> <pre><code>class App: def __init__(self, ...): self.canvas = Tkinter.Canvas(...) self.thingy = SomethingElse() class SomethingElse: def __init__(self, parentApp): self.parentApp = parentApp def drawSomething(self): self.parentApp.canvas.create_oval(...) a = App(...) s = SomethingElse(a) s.drawSomething() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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