[Tutor] Problems with GUI calling a class
David Holland
davholla2002 at yahoo.co.uk
Sat Oct 16 17:32:44 CEST 2004
I wrote a program to calculate the likely result of a
one day cricket match and then decided to make it into
a class and have another class for a GUI.
It all works well but I can not call the function from
the first class from the GUI class, insteading of
returning a result it just gives this error 'Exception
in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.3/lib-tk/Tkinter.py", line
1345, in __call__
return self.func(*args)
File
"/home/david/Documents/pyprogramming/cricketv6.py",
line 194, in cricket_getinfo
self.results_txt.insert(0.0,results)
UnboundLocalError: local variable 'results' referenced
before assignment
'
This is the code which create the GUI and if it worked
would call the calculations.
def cricket_getinfo(self):
"""Get values from the GUI and submit for
calculation"""
print "test"
runs = self.runs_ent.get()
wickets = self.wickets_ent.get()
overs = self.overs_ent.get()
if self.yes_no.get():
used_before = 'Y'
else:
used_before = 'N'
Cricketobj = Cricket()
#create code to call the calculations
z = 50
win = 10
if self.yes_no == 'N':
win = 10
originalscore = 0
wold = 0
yold = 0
results =
Cricketobj.runfuns(wickets,overs,runs,z, win,
originalscore, orignovoers, wold, yold)
print results
elif self.yes_no == 'Y':
#get the data from last time
xold, yold, wold = openlasttime()
#now we are calculating using the more up to
date run rate
orignovoers = y
runs = int(runs)
xold = int(xold)
x = x - xold
overs = int(overs) - int(yold)
wickets = int(wickets) - int(wold)
wold = int(wold)
win = 10
z = 50
results =
Cricketobj.runfuns(wickets,overs,runs,z, win,
originalscore, orignovoers, wold, yold)#(w,y,x,z,win,
xold, orignovoers, wold, yold)
#the line below is causing it crash
#results = 1
self.results_txt.insert(0.0,results)
Cricketobj.savecurrentstate(runs,overs,wickets)
Can anyone see why I am not calling the class's
function properly ?
Thanks in advance.
David
___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
More information about the Tutor
mailing list