Your coding style here is not the style used in wxPython. Check the samples; people use an object-based scheme, rather than just linearly creating windows, frames, and controls at the global level. You are going to find it difficult to map the many available examples to your non-class coding style.
Two of your biggest problems are related to your calls to Bind, and I don't believe this would have worked in wxPHP either. When you do this:
trayicon.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, trayicon_clicked(frame))
it does not do what you think. You are thinking that this will cause the LEFT_DOWN event to call trayicon_clicked(frame). Instead, what this does is call trayicon_clicked(frame) immediately, then pass the return value to trayicon.Bind. That's wrong, and it happens every time you call Bind. That's why you see the immediate calls.
Even more than that, you are calling Bind incorrectly. You can't pass arbitrary parameters to a bound event handler. Your event handler will be passed an event object derived from wx.Event, and that's it. That's why people use classes; they can pass a method bound to a class instance, and they can store state in that class instance. In your case, you have to do:
frame.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, trayicon_clicked)
and
frame.Bind(wx.EVT_FILEPICKER_CHANGED, picker_changed, filepicker)
and
top_panel.Bind(wx.EVT_BUTTON, button_clicked, button )
and
frame.Bind(wx.EVT_TIMER, every_second)
Next, since your event handlers are not going to receive the parameters you're trying to pass, you should change their definitions to
def button_clicked(evt):
def picker_changed(evt):
def trayicon_clicked(evt):
def every_second(evt):
Fortunately, since you have your windows and controls stored in globals, you can access them by name, just like you have it in the code.
Next, you create both an hbox and vbox, and you try to call frame.SetSizer with both. A frame can only have one sizer at a time. The hbox is useless, so just delete it.
Next, you have this:
photo_frame = wx.Panel(top_panel, -1)
photo_frame.SetSize(wx.Size(photo_frame_width, photo_frame_height))
photo_frame.SetBackgroundColour("#000000")
photo_frame = wx.StaticBitmap(photo_frame, -1, photo)
vbox.Add(photo_frame, 0, wx.ALL, 10)
You create a Panel. Then, you create a StaticBitmap owned by that Panel, but you store that bitmap into the same variable as the panel, so you've lost the panel. What you are adding to the vbox is the static bitmap, not the panel. The panel is not really necessary, so I changed this to:
#photo_frame = wx.Panel(top_panel, -1)
#photo_frame.SetSize(wx.Size(photo_frame_width, photo_frame_height))
#photo_frame.SetBackgroundColour("#000000")
photo_frame = wx.StaticBitmap(photo_frame, -1, photo)
photo_frame.SetSize(wx.Size(photo_frame_width, photo_frame_height))
vbox.Add(photo_frame, 0, wx.ALL, 10)
Next, you add all of the controls to the top_panel, but you attach the vbox to the frame. You need to set the sizer on the panel that actually owns the controls to be managed. So, instead of this:
frame.SetSizer(hbox)
frame.SetSizer(vbox)
frame.Layout()
frame.SetAutoLayout(True)
frame.Show(True)
Do this:
#frame.SetSizer(hbox)
top_panel.SetSizer(vbox)
top_panel.Layout()
top_panel.SetAutoLayout(True)
frame.Show(True)
With all of those changes, your code seems to work for me, but you should really think about learning how to use wxPython with classes.
···
On Apr 12, 2019, at 9:13 PM, Dave Kimble <dave.kimble.2@gmail.com> wrote:
In wxPHP I built up a template file with snippets of useful code, constructing controls, etc.,
now in wxPython, I am trying to rebuild that template file (attached).
When I run the file, virtually every control has something that doesn't work about it.
—
Tijm Roberts, timr@probo.com
Providenza & Boekelheide, Inc.