a | b | |
---|
| 0 | + | '''Physics problem Solver |
---|
| 0 | + | |
---|
| 0 | + | Finds Distance, Time or Speed according to input |
---|
| 0 | + | ''' |
---|
| 0 | + | |
---|
| 0 | + | import wx |
---|
| 0 | + | import math |
---|
| 0 | + | |
---|
| 0 | + | class MyFrame(wx.Frame): |
---|
| 0 | + | def __init__(self, parent, id, title): |
---|
| 0 | + | wx.Frame.__init__(self, parent, id, title) |
---|
| 0 | + | panel=wx.Panel(self, -1) |
---|
| 0 | + | |
---|
| 0 | + | label1= wx.StaticText(panel, -1, 'Speed (kmph):') |
---|
| 0 | + | label2= wx.StaticText(panel, -1, 'Distance (km):') |
---|
| 0 | + | label3= wx.StaticText(panel, -1, 'Time (hours):') |
---|
| 0 | + | label4= wx.StaticText(panel, -1, 'Enter zero for the value you want to find.') |
---|
| 0 | + | |
---|
| 0 | + | self.speed= wx.TextCtrl(panel, -1, '0') |
---|
| 0 | + | self.distance= wx.TextCtrl(panel, -1, '0') |
---|
| 0 | + | self.time= wx.TextCtrl(panel, -1, '0') |
---|
| 0 | + | |
---|
| 0 | + | self.calcBtn= wx.Button(panel, -1, 'Calculate') |
---|
| 0 | + | self.calcBtn.Bind(wx.EVT_BUTTON, self.onCalc) |
---|
| 0 | + | |
---|
| 0 | + | # use gridbagsizer for layout of widgets |
---|
| 0 | + | sizer = wx.GridBagSizer(vgap=5, hgap=10) |
---|
| 0 | + | sizer.Add(label4, pos=(0, 0)) |
---|
| 0 | + | sizer.Add(label1, pos=(2, 0)) |
---|
| 0 | + | sizer.Add(self.speed, pos=(2, 1)) # row 0, column 1 |
---|
| 0 | + | sizer.Add(label2, pos=(3, 0)) |
---|
| 0 | + | sizer.Add(self.distance, pos=(3, 1)) |
---|
| 0 | + | sizer.Add(label3, pos=(4, 0)) |
---|
| 0 | + | sizer.Add(self.time, pos=(4, 1)) |
---|
| 0 | + | sizer.Add(self.calcBtn, pos=(5, 0), span=(1, 2)) |
---|
| 0 | + | |
---|
| 0 | + | # use boxsizer to add border around sizer |
---|
| 0 | + | border = wx.BoxSizer() |
---|
| 0 | + | border.Add(sizer, 0, wx.ALL, 20) |
---|
| 0 | + | panel.SetSizerAndFit(border) |
---|
| 0 | + | self.Fit() |
---|
| 0 | + | |
---|
| 0 | + | |
---|
| 0 | + | def onCalc(self, event): |
---|
| 0 | + | #self.speed.SetValue('Working!!') |
---|
| 0 | + | |
---|
| 0 | + | if (self.speed.GetValue())=='0': # find speed |
---|
| 0 | + | self.speed.SetValue(str(float(self.distance.GetValue())/float(self.time.GetValue()))) # set speed |
---|
| 0 | + | elif (self.distance.GetValue())=='0': #find distance |
---|
| 0 | + | self.distance.SetValue(str(float(self.speed.GetValue())*float(self.time.GetValue()))) # set speed |
---|
| 0 | + | elif (self.time.GetValue())=='0': #find time |
---|
| 0 | + | self.time.SetValue(str(float(self.distance.GetValue())/float(self.speed.GetValue()))) # set time |
---|
| 0 | + | |
---|
| 0 | + | #else: |
---|
| 0 | + | #self.label4.SetValue('You did not enter zero for any value') |
---|
| 0 | + | |
---|
| 0 | + | app=wx.App() |
---|
| 0 | + | frame= MyFrame(None, -1, 'Physics Problem Solver') |
---|
| 0 | + | frame.Show() |
---|
| 0 | + | app.MainLoop() |
---|
| 0 | + | |
---|
| 0 | + | |
---|
| 0 | + | |
---|
| 0 | + | |
---|
... | |
---|