Python Forum
[WxPython] [Very Basic Example Only] Hello World - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Tutorials (https://python-forum.io/forum-4.html)
+---- Forum: GUI tutorials (https://python-forum.io/forum-34.html)
+---- Thread: [WxPython] [Very Basic Example Only] Hello World (/thread-270.html)



[Very Basic Example Only] Hello World - Yoriz - Oct-03-2016

import wx

app = wx.App(False)

frame = wx.Frame(None, -1, 'Hello World')
frame.Show()

app.MainLoop()



RE: [wxPython Example] Hello World very basic - j.crater - Oct-03-2016

I would fancy that. In fact I am trying to get my head around getting wyPython to work with Python 3 ATM.


RE: [wxPython Example] Hello World very basic - nilamo - Oct-05-2016

I think this should have some comments describing what all the magic values are. Like, -1? lol?


RE: [wxPython Example] Hello World very basic - Yoriz - Oct-08-2016

  • none is telling the frame there is no parent widget
  • -1 tells the frame to automatically assign a new unique id value
  • 'Hello World' is the caption that will be displayed in the frames title bar
see the frame documentation


RE: [wxPython Example] Hello World very basic - nilamo - Oct-08-2016

Is there any reason at all you wouldn't use -1?


RE: [wxPython Example] Hello World very basic - Yoriz - Oct-08-2016

About the only time I don't use -1 for the id is for menu and toolbar items.
for instance my menu and toolbar has an edit the menu item would use wx.ID_EDIT.
menu_edit = wx.MenuItem(menu_edit_group, wx.ID_EDIT, 'Edit',
    'Edit the selected item')
and then the toolbar widget would be
tool_bar.AddTool(wx.ID_EDIT, 'Edit', page_edit16.GetBitmap(), wx.NullBitmap,
    wx.ITEM_NORMAL, 'Edit the selected item', 'Edit the selected item')
then an event that enables/disable the controls         
self.Bind(wx.EVT_UPDATE_UI, self.on_update_on_selection, id=wx.ID_EDIT)
which is bound to
def on_update_on_selection(self, event):
    event.Enable(self.has_selection)
In general setting your own id is not needed because you access the widget by the python object linked to them.
The id is just used internally by wxwidgets to track widgets and tie events to widgets ect.

Note: there is a default attribute that can be used which has a value of -1
>>> wx.ID_ANY
-1