免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1632 | 回复: 3
打印 上一主题 下一主题

wxpython help ... [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-14 06:13 |只看该作者 |倒序浏览
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()

论坛徽章:
0
2 [报告]
发表于 2009-08-14 21:55 |只看该作者
1,不明白为何要定义两次panel = wx.Panel(self);
2,TextCtrl(),不是有SetValue()?为何不用之?

论坛徽章:
0
3 [报告]
发表于 2009-08-14 22:40 |只看该作者
To Q1, inside Oncalc(), need a panel to use in self.tCalc = wx.TextCtrl(panel,...)

To Q2, I'm quite new to wxpython, please drop me a few of lines if you could. many thanks !!!

论坛徽章:
0
4 [报告]
发表于 2009-08-14 22:54 |只看该作者
fixed it. done.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP