请教wxpython小程序问题

#!/usr/bin/python#-*-coding:cp936-*-#Filename:calculator.pyimportwxclassMyFrame(wx.Fr... #!/usr/bin/python
# -*- coding: cp936 -*-
# Filename : calculator.py

import wx

class MyFrame ( wx.Frame ):

def __init__ ( self ):

wx.Frame.__init__ ( self, None, -1, u'计算器1.0' )

panel = wx.Panel ( self, -1 )

sizer = wx.GridBagSizer ( hgap = 1, vgap = 1 )

display = wx.TextCtrl ( panel, -1, '0.', style = wx.TE_READONLY | wx.TE_RIGHT )

display.SetMaxLength ( 5 )

sizer.Add ( display, ( 0, 0 ), ( 1, 5 ), wx.EXPAND )

buttons = [ [ None, None, None, None, None ], \

[ [ 'M+', 100 ], [ '1', 1 ], [ '2', 2 ], [ '3', 3 ], [ '+', 200 ] ], \

[ [ 'M-', 101 ], [ '4', 4 ], [ '5', 5 ], [ '6', 6 ], [ '-', 201 ] ], \

[ [ 'MR', 102 ], [ '7', 7 ], [ '8', 8 ], [ '9', 9 ], [ '*', 202 ] ], \

[ [ 'MC', 103 ], [ '.', 120 ], [ '0', 0 ], [ '=', 104 ], [ '/', 203 ] ], \

[ None, None, [ 'B', 105 ], [ '+/-', 106 ], [ 'sqrt', 204 ] ] ]

x = y = 0

for row in buttons:

for button in row:

if button == None:

x = x + 1

continue

sizer.Add ( wx.Button ( panel, button [ 1 ], button [ 0 ], size = ( 30, 30 ) ), pos = ( y, x ) )

self.Bind ( wx.EVT_BUTTON, self.handler, button [ 1 ] )

x = x + 1

x = 0

y = y + 1

panel.SetSizer ( sizer )

panel.Fit ()

self.SetClientSize ( panel.GetSize() )

self.Centre ()

self.memory = 0

def handler ( self, event ):

id = event.GetId()

if ( id >= 0 ) and ( id <= 9 ):

if display.GetValue() == '0.':

display.SetValue ( '' )

display.AppendText ( str ( id ) )

elif id == 100:

self.memory = float ( display.GetValue() )

if __name__ == '__main__':

app = wx.PySimpleApp()

frame = MyFrame()

frame.Show()

app.MainLoop()
为什么运行后总是提示GetId方法出错?我的环境是IDLE python2.6.4,没有分了,还请好心人帮帮我这个新手
展开
 我来答
gaodayongwd
2010-01-13
知道答主
回答量:4
采纳率:0%
帮助的人:6882
展开全部
id = event.GetEventObject().GetId()
试试这个
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式