SHARE
TWEET

Python GUI

sudojesse Jun 16th, 2012 61 Never
  1. #!/usr/bin/env python-32
  2.  
  3. import wx
  4.  
  5. try:
  6.     with open('mydata.txt', 'r+') as data:
  7.         myData = data.read()
  8. except IOError:
  9.     data = open('mydata.txt','w')
  10.     myData = ''
  11.     data.close()
  12.  
  13. def save(event):
  14.     with open('mydata.txt', 'w') as data:
  15.         data.write(textArea.GetValue())
  16.  
  17. app = wx.App()
  18.  
  19. frame = wx.Frame(None, title="hello world!", size=(400,400))
  20. frame.Show()
  21.  
  22. helloButton = wx.Button(frame, label="save", pos=(160,20),size=(80,20))
  23. helloButton.Bind(wx.EVT_BUTTON, save)
  24.  
  25. textArea = wx.TextCtrl(frame, style=wx.TE_MULTILINE, pos=(20,100), size=(360,250))
  26. textArea.SetValue(myData)
  27.  
  28. app.MainLoop()
RAW Paste Data
Top