- 论坛徽章:
- 0
|
请看下面这段代码,我希望实现当按下“计算”按钮的时候,对data1和data2的数据进行计算,比如相加,然后把结果输出在同一个界面里,应该怎么实现?
我想的是,当按下“计算”后,在位置(10, 140)生成一个wx.StaticText, 然后把结果显示出来,但是还没成功,谁能指导一下?
- #!/usr/bin/env python
- #-*- coding:utf-8 -*-
- import wx
- class RefactorExample(wx.Frame):
- def __init__(self, parent, id):
- wx.Frame.__init__(self, parent, id, 'Refactor Example',
- size=(340, 200))
- panel = wx.Panel(self, -1)
- panel.SetBackgroundColour("White")
- self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- self.createButtonBar(panel)
- self.createTextFields(panel)
- def buttonData(self): #按钮栏数据
- return (("计算", self.OnFirst), ("关闭", self.OnLast))
- #创建按钮
- def createButtonBar(self, panel, yPos = 70):
- xPos = 50
- for eachLabel, eachHandler in self.buttonData():
- pos = (xPos, yPos)
- button = self.buildOneButton(panel, eachLabel,
- eachHandler, pos)
- xPos += button.GetSize().width
- def buildOneButton(self, parent, label, handler, pos=(0,0)):
- button = wx.Button(parent, -1, label, pos)
- self.Bind(wx.EVT_BUTTON, handler, button)
- return button
- def textFieldData(self): #文本数据
- return (("Data1:", (10, 10)),
- ("Data2:", (10, 40)))
- #创建文本
- def createTextFields(self, panel):
- for eachLabel, eachPos in self.textFieldData():
- self.createCaptionedText(panel, eachLabel, eachPos)
- def createCaptionedText(self, panel, label, pos):
- static = wx.StaticText(panel, wx.NewId(), label, pos)
- static.SetBackgroundColour("White")
- textPos = (pos[0] + 75, pos[1])
- wx.TextCtrl(panel, wx.NewId(), "", size=(140, -1), pos=textPos)
- # 空的事件处理器放在一起
- def OnLast(self, event):
- self.Close(True)
- def OnFirst(self, event): pass
- def OnCloseWindow(self, event):
- self.Destroy()
- if __name__ == '__main__':
- app = wx.PySimpleApp()
- frame = RefactorExample(parent=None, id=-1)
- frame.Show()
- app.MainLoop()
复制代码 |
|