IT-Academy

Prevod teploty

Feb 2nd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. import wx
  2.  
  3.  
  4. class Example(wx.Frame):
  5.            
  6.     def __init__(self, *args, **kw):
  7.         super(Example, self).__init__(*args, **kw)
  8.        
  9.         self.InitUI()
  10.        
  11.     def InitUI(self):  
  12.  
  13. ##        pnl = wx.Panel(self)
  14.  
  15.        
  16.         wx.StaticText(self, label='Convert Fahrenheit temperature to Celsius',
  17.             pos=(20,20))
  18.         wx.StaticText(self, label='Fahrenheit: ', pos=(20, 80))
  19.         wx.StaticText(self, label='Celsius: ', pos=(20, 150))
  20.        
  21.         self.celsius = wx.StaticText(self, label='', pos=(150, 150))
  22.         self.sc = wx.SpinCtrl(self, value='0', pos=(150, 75), size=(60, -1))
  23.         self.sc.SetRange(-459, 1000)
  24.        
  25.         btn = wx.Button(self, label='Compute', pos=(70, 230))
  26.         btn.SetFocus()
  27.         cbtn = wx.Button(self, label='Close', pos=(185, 230))
  28.  
  29.         btn.Bind(wx.EVT_BUTTON, self.OnCompute)
  30.         cbtn.Bind(wx.EVT_BUTTON, self.OnClose)
  31.            
  32.         self.SetSize((350, 310))
  33.         self.SetTitle('wx.SpinCtrl')
  34.         self.Centre()
  35.         self.Show(True)          
  36.        
  37.     def OnClose(self, e):
  38.        
  39.         self.Close(True)    
  40.        
  41.     def OnCompute(self, e):
  42.        
  43.         fahr = self.sc.GetValue()
  44.         cels = round((fahr - 32) * 5 / 9.0, 2)
  45.         self.celsius.SetLabel(str(cels))        
  46.                      
  47. def main():
  48.    
  49.     ex = wx.App()
  50.     Example(None)
  51.     ex.MainLoop()    
  52.  
  53. if __name__ == '__main__':
  54.     main()
Advertisement
Add Comment
Please, Sign In to add comment