- 论坛徽章:
- 0
|
Hi ! below is a simple code that I modified from WWW.
as I run it, first time after I enter a number, it calcutes correct !
from second time on , regardless of whatever I enter a number, it calcutes wrong !
I trace it , seems self.tCalc.GetValue() not effect ! I'm confusing about it. please help
& indicate what it is going wrong here. thanks a lot.
#!/usr/bin/python
import wx
# --- Define a custom Frame, this will become the main window ---
class CalcFrame(wx.Frame):
def __init__(self, parent, id, title, pos, size):
wx.Frame.__init__(self, parent, id, title, pos, size)
# we need a panel to get the right background
panel = wx.Panel(self)
# Now create the text and button widgets
self.tCalc = wx.TextCtrl(panel, -1, "", pos=(3,3), size=(185,22))
bClear = wx.Button(panel, -1, "Calc", pos=(15, 32))
self.Bind(wx.EVT_BUTTON, self.OnCalc, bClear)
bQuit = wx.Button(panel, -1, "Quit", pos=(100, 32))
self.Bind(wx.EVT_BUTTON, self.OnQuit, bQuit)
# these are our event handlers
def OnCalc(self, event):
print ".. 1 .."
panel=wx.Panel(self)
f=self.tCalc.GetValue()
print 'f=',f
c=5.0*(float(f) - 32.0)/9.0
print 'c=',c
self.tCalc = wx.TextCtrl(panel, -1, str(c), pos=(3,3), size=(185,22))
#self.Update()
print ".. 2 .."
def OnQuit(self, event):
self.Destroy()
# --- Define the Application Object ---
# Note that all wxPython programs MUST define an
# application class derived from wx.App
class CalcApp(wx.App):
def OnInit(self):
frame = CalcFrame(None, -1, "F2C", (200,50), (200,90) )
frame.Show(True)
self.SetTopWindow(frame)
return True
# create instance and start the event loop
CalcApp(True,"debug.txt").MainLoop() |
|