Advertisement
gruntfutuk

wx_first_test

Feb 13th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import sys
  2. import wx
  3.  
  4.  
  5. class MyForm(wx.Frame):
  6.  
  7.     def __init__(self):
  8.         wx.Frame.__init__(self, None,
  9.                           title="wxPython Redirect Tutorial")
  10.  
  11.         # Add a panel so it looks the correct on all platforms
  12.         panel = wx.Panel(self, wx.ID_ANY)
  13.         style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL
  14.         output = wx.TextCtrl(panel, wx.ID_ANY, size=(500, 500),
  15.                           style=style)
  16.         btn = wx.Button(panel, wx.ID_ANY, 'Push me!')
  17.         self.Bind(wx.EVT_BUTTON, self.onButton, btn)
  18.  
  19.         # Add widgets to a sizer
  20.         sizer = wx.BoxSizer(wx.VERTICAL)
  21.         sizer.Add(output, 1, wx.ALL | wx.EXPAND, 5)
  22.         sizer.Add(btn, 0, wx.ALL | wx.CENTER, 5)
  23.         panel.SetSizer(sizer)
  24.  
  25.         # redirect text here
  26.         sys.stdout = output
  27.  
  28.         for i in range(1, 13):
  29.             for j in range(1, 13):
  30.                 print(f'{i:3d} x {j:3d} = {i*j:3d}')
  31.  
  32.     def onButton(self, event):
  33.         print
  34.         "You pressed the button!"
  35.  
  36.  
  37. # Run the program
  38. if __name__ == "__main__":
  39.     app = wx.App(False)
  40.     frame = MyForm().Show()
  41.     app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement