As I understand, wx.html.HtmlWindow
does not support the standard <input type="checkbox">
tag, and the way to add checkboxes is something like this:
import wx
import wx.html as html
import wx.lib.wxpTag
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(500, 500))
self.control = html.HtmlWindow(self, size=(500, 500))
self.windowSizer = wx.BoxSizer()
self.windowSizer.Add(self.control, 1, wx.ALL|wx.EXPAND)
content = r'''<html><head></head><body>
Some text first<br>
<wxp module="wx" class="CheckBox">
<param name="id" value="1">
<param name="name" value="MyName">
<param name="label" value="MyLabel">
</wxp><br>
<wxp module="wx" class="CheckBox"><param name="id" value="2"></wxp><br>
<wxp module="wx" class="CheckBox"><param name="id" value="3"></wxp><br>
</body></html>
'''
self.control.SetPage(content)
self.SetSizerAndFit(self.windowSizer)
self.control.Bind(wx.EVT_CHECKBOX, self.OnCheck)
def OnCheck(self, evt):
print(f"{evt.Id} checked: {evt.IsChecked()}")
if __name__ == '__main__':
app = wx.App()
frame = MainWindow(None, -1, "Window")
frame.Show(1)
app.MainLoop()
How do I create a box that is already checked (or check it programmatically immediately after it is created)? The parameters used in <param name...>
seem to be from the CheckBox
’s __init__
function, and there’s no parameter to create it already checked. I’ve tried getting the control through wx.window.FindWindowByName/Label/Id
to call SetValue
on it, but to no avail.