Advertisement
Guest User

wx_blog_demo.py

a guest
Sep 23rd, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import wx
  2.  
  3. #import the newly created GUI file
  4. import gui
  5.  
  6. #importing * : to enable writing sin(13) instead of math.sin(13)
  7. from math import *
  8.  
  9. #inherit from the MainFrame created in wxFowmBuilder and create CalcFrame
  10. class CalcFrame(gui.MainFrame):
  11.     #constructor
  12.     def __init__(self,parent):
  13.         #initialize parent class
  14.         gui.MainFrame.__init__(self,parent)
  15.  
  16.     #what to when 'Solve' is clicked
  17.     #wx calls this function with and 'event' object
  18.     def solveFunc(self,event):
  19.        
  20.         #evaluate the string in 'text' and put the answer back
  21.         ans = eval(self.text.GetLabel())
  22.         self.text.SetLabel (str(ans))
  23.         print str(ans)
  24.     #put a blank string in text when 'Clear' is clicked
  25.     def clearFunc(self,event):
  26.         self.text.SetLabel("")
  27.  
  28. #mandatory in wx, create an app, False stands for not deteriction stdin/stdout
  29. #refer manual for details
  30. app = wx.App(False)
  31.  
  32. #create an object of CalcFrame
  33. frame = CalcFrame(None)
  34. #show the frame
  35. frame.Show(True)
  36. #start the applications
  37. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement