SHARE
TWEET

guiFix

a guest Oct 16th, 2014 238 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #importing wx files
  2. import wx
  3.  
  4. #import the newly created GUI file
  5. import gui
  6.  
  7. #importing * : to enable writing sin(13) instead of math.sin(13)
  8. from math import *
  9.  
  10. #inherit from the MainFrame created in wxFowmBuilder and create CalcFrame
  11. class CalcFrame(gui.MainFrame):
  12.     #constructor
  13.     def __init__(self,parent):
  14.         #initialize parent class
  15.         gui.MainFrame.__init__(self,parent)
  16.  
  17.     #what to do when 'Solve' is clicked
  18.     #wx calls this function with and 'event' object
  19.     def solveFunc(self,event):
  20.         try:
  21.                 #evaluate the string in 'text' and put the answer back
  22.                 ans = eval(self.text.GetValue())
  23.                 self.text.SetValue(str(ans))
  24.         except Exception:
  25.                 self.text.SetValue(str("I need math"))
  26.     #put a blank string in text when 'Clear' is clicked
  27.     def clearFunc(self,event):
  28.         self.text.SetValue(str())
  29.  
  30. #mandatory in wx, create an app, False stands for not deteriction stdin/stdout
  31. #refer manual for details
  32. app = wx.App(False)
  33.  
  34. #create an object of CalcFrame
  35. frame = CalcFrame(None)
  36. #show the frame
  37. frame.Show(True)
  38. #start the applications
  39. app.MainLoop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top