Python/wxPython/QuickStart: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
Line 47: Line 47:
</source>
</source>
|}
|}
== wxMDIParentFrame without XRC ==
<source lang="python">
#!/usr/bin/env python3
import wx
class MyApp(wx.App):
    def OnInit(self):
        frame = wx.MDIParentFrame(None, -1, 'Hello World!')
        frame.Show()
        return True
if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()
</python>


== wxMDIParentFrame with XRC ==
== wxMDIParentFrame with XRC ==

Revision as of 09:01, 20 March 2019

Skeleton

wxFrame without XRC

#!/usr/bin/env python3
import wx

class MyApp(wx.App):
    def OnInit(self):
        frame = wx.Frame(None, -1, 'Hello World!')
        frame.Show()
        return True

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()

wxFrame with XRC

Python (main.py) XRC (layout.xrc)
#!/usr/bin/env python3
import wx.xrc

class MyApp(wx.App):
    def OnInit(self):
        res = wx.xrc.XmlResource('layout.xrc')
        frame = res.LoadFrame(None, 'mainFrame')
        frame.Show()
        return True

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()
<?xml version="1.0" encoding="utf-8"?>
<resource version="2.9.0.5">
  <object name="mainFrame" class="wxFrame">
    <title>Hello World!</title>
  </object>
</resource>

wxMDIParentFrame without XRC

#!/usr/bin/env python3
import wx

class MyApp(wx.App):
    def OnInit(self):
        frame = wx.MDIParentFrame(None, -1, 'Hello World!')
        frame.Show()
        return True

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()
</python>

== wxMDIParentFrame with XRC ==
{| class="wikitable"
|-
! Python (main.py) || (layout.py)
|-
| 
<source lang="python">
#!/usr/bin/env python3
import wx.xrc

class MyApp(wx.App):
    def OnInit(self):
        res = wx.xrc.XmlResource('layout.xrc')
        frame = res.LoadObject(None, 'mainFrame', 'wxMDIParentFrame')
        frame.Show()
        return True

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()

|

<?xml version="1.0" encoding="utf-8"?>
<resource version="2.9.0.5">
  <object name="mainFrame" class="wxMDIParentFrame">
    <title>Hello World!</title>
  </object>
</resource>

|}