Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import wx
- class MyForm(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self, None,
- title="wxPython Redirect Tutorial")
- # Add a panel so it looks the correct on all platforms
- panel = wx.Panel(self, wx.ID_ANY)
- style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL
- output = wx.TextCtrl(panel, wx.ID_ANY, size=(500, 500),
- style=style)
- btn = wx.Button(panel, wx.ID_ANY, 'Push me!')
- self.Bind(wx.EVT_BUTTON, self.onButton, btn)
- # Add widgets to a sizer
- sizer = wx.BoxSizer(wx.VERTICAL)
- sizer.Add(output, 1, wx.ALL | wx.EXPAND, 5)
- sizer.Add(btn, 0, wx.ALL | wx.CENTER, 5)
- panel.SetSizer(sizer)
- # redirect text here
- sys.stdout = output
- for i in range(1, 13):
- for j in range(1, 13):
- print(f'{i:3d} x {j:3d} = {i*j:3d}')
- def onButton(self, event):
- print
- "You pressed the button!"
- # Run the program
- if __name__ == "__main__":
- app = wx.App(False)
- frame = MyForm().Show()
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement