I modified a little example found on this nice website :
http://zetcode.com/wxpython/events/
The structure is simple, 2 input boxes and a button the get the result of the sum.
Obiouvsly you need wxPython installed to make it work.
This is the code:
#!/usr/bin/python
# Sum of 2 numbers
import wx
class Sum_2_numbers(wx.Frame):
def __init__(self, parent, id, title ):
wx.Frame.__init__(self, parent, id, title, size=(320, 230))
wx.StaticText(self, -1, 'Number 1:', (30,25))
wx.StaticText(self, -1, 'Number 2:', (30,65))
wx.StaticText(self, -1, 'Sum:', (30,180))
self.in1 = wx.TextCtrl(self, -1, 'put a number', (100,20),size=(100,30))
self.in2 = wx.TextCtrl(self, -1, 'put a number', (100,60),size=(100,30))
self.st3 = wx.StaticText(self, -1, '', (100, 180))
self.Button = wx.Button(self, -1, "Sum !", wx.Point(80,120),size = (120,30))
self.Bind(wx.EVT_BUTTON, self.OnClick)
self.Centre()
self.Show(True)
def OnClick(self, event):
a = float(self.in1.GetValue())
b = float(self.in2.GetValue())
self.st3.SetLabel(str(a+b))
app = wx.App()
Sum_2_numbers(None, -1, 'Tool for summing 2 numbers...')
app.MainLoop()
Nessun commento:
Posta un commento