def correct(): num_good.set(num_good.get()+1) sc.play()
I'm pulling this from my code, but if you need an exact reference, it would be on page 253.
Ok, so I'm not so much saying that it doesn't work, I just want to know why, and how were we supposed to get to this without looking at the answer.
I tried working my way through Head First Java, and made it up to the point of encapsulation. When I see get/set, that's what I'm thinking. Is this an example of encapsulation?
Also, I feel as though this is using methods before defining them, for instance, don't we need to define the num_good.set() and num_good.get(), or are we defining them in using the code?
Also (again, I know) why did this have to be done at all? My original thought was to save the methods from before :
def wrong(): global number_wrong global number_asked number_asked = number_asked + 1 number_wrong = number_wrong + 1 sw.play()
then I realized that I need to get:
number_wrong = IntVar()
into the code. Of course, this is where the whole thing gets messed up. Unless I can add it into the method.
Still, I don't see how we were supposed to get the whole get/set part of the code by ourselves. Can someone explain the thought process that would lead to doing this without actually looking at the answer, or perhaps give me a version of the code that would work that doesn't use this method? Thanks!