请教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,没有分了,还请好心人帮帮我这个新手 展开
# -*- 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,没有分了,还请好心人帮帮我这个新手 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询