How to create a small sample application (Phoenix)

Keywords : Application, Small runnable sample application.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Application :

First example

img_sample_one.png

   1 # sample_one.py
   2 
   3 """
   4 
   5 Author : Robin Dunn
   6 Link : https://www.wxpython.org/pages/overview/#hello-world
   7 
   8 """
   9 
  10 # First things. Import the wxPython package.
  11 import wx
  12 
  13 #---------------------------------------------------------------------------
  14 
  15 # Next, create an application object.
  16 # Enable or disable stdout/stderr.
  17 app = wx.App(redirect=False)
  18 
  19 # Then a frame.
  20 frm = wx.Frame(None, title="Hello World")
  21 
  22 # Show it.
  23 frm.Show(True)
  24 
  25 # Start the event loop.
  26 app.MainLoop()


Second example

[ATTACH]

   1 # sample_two.py
   2 
   3 """
   4 
   5 Author : Robin Dunn
   6 Link : https://www.wxpython.org/pages/overview/#hello-world
   7 
   8 """
   9 
  10 import wx; a=wx.App(); wx.Frame(None, title="Hello World").Show(); a.MainLoop()


Third example

[ATTACH]

   1 # sample_three.py
   2 
   3 import wx
   4 
   5 #---------------------------------------------------------------------------
   6 
   7 class MyFrame(wx.Frame):
   8     """
   9     ...
  10     """
  11     def __init__(self, *args, **kwargs):
  12         wx.Frame.__init__(self, *args, **kwargs)
  13 
  14         panel = wx.Panel(self, -1)
  15 
  16 #---------------------------------------------------------------------------
  17 
  18 if __name__ == '__main__':
  19      app = wx.App()
  20      frame = MyFrame(None, title="Hello World")
  21      frame.Show()
  22      app.MainLoop()


Fourth example

[ATTACH]

   1 # sample_four.py
   2 
   3 import wx
   4 
   5 #---------------------------------------------------------------------------
   6 
   7 class MyFrame(wx.Frame):
   8     """
   9     We simply derive a new class of Frame.
  10     """
  11     def __init__(self, parent, title):
  12         wx.Frame.__init__(self, parent, title=title)
  13 
  14         panel = wx.Panel(self, -1)
  15 
  16 #---------------------------------------------------------------------------
  17 
  18 class MyApp(wx.App):
  19     """
  20     We create an application object.
  21     """
  22     def OnInit(self):
  23 
  24         #------------
  25 
  26         frame = MyFrame(None, "Hello World")
  27         self.SetTopWindow(frame)
  28         frame.Show(True)
  29 
  30         return True
  31 
  32 #---------------------------------------------------------------------------
  33 
  34 def main():
  35     app = MyApp(False)
  36     app.MainLoop()
  37 
  38 #---------------------------------------------------------------------------
  39 
  40 if __name__ == "__main__" :
  41     main()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

The wxPython community...


About this page

Date (d/m/y) Person (bot) Comments :

22/10/20 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a small sample application (Phoenix) (last edited 2020-12-13 14:53:52 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.