For a wxPython app I'm creating, I need for there to be a variable that counts the number of cycles that the program goes through. I have multiple panels which are defined in their own class. The frame class creates an instance of them all and the panels are shown or hidden depending on what buttons the user clicks. For the bulk of the program, the "game" rotates through three panels (which I'll call p1, p2 and p3). When you reach p3, the program takes you back to p1 *\if you have gone through the cycle under a certain amount of time. Also, it keeps track of other data as t开发者_开发问答he program is run. My problem is that I'm not sure how to keep track of this data. I've tried having class variables in my frame class which would presumable be accessible to all of the panels by using the GetParent() method but I have had limited luck with that approach. I've also tried using global variables but this has also led to a dead end. Any information on how I could possibly accomplish this would be greatly appreciated.
I can think of no reason why global variables wouldn't work unless you are spawning subprocesses. To avoid having to declare the globals, put them in an object like a dict:
myglobals = {'count': 0}
class whatever:
def blather():
myglobals['count'] += 1
精彩评论