I'm using wxPython to create a GUI app. Right now I'm using a wx.CheckListBox to display options with check boxes, but I'd like the text in the CheckListBox to be formatted usin开发者_如何学Gog HTML. What's the best way to go about this?
Replace wxCheckListBox with wxHtmlWindow and use wxpTag for the check boxes.
Here is some code to get you started.
import wx
import wx.lib.wxpTag
class HtmlCheckListBox(wx.html.HtmlWindow):
def __init__(self, parent, choices=None):
wx.html.HtmlWindow.__init__(self, parent)
check_box = """
<wxp module="wx" class="CheckBox">
<param name="id" value="%d">
</wxp>
"""
self._ids = dict()
if choices:
items = list()
for c, choice in enumerate(choices):
i = wx.NewId()
self._ids[i] = c
items.append((check_box % i) + choice)
self.SetPage("<hr>".join(items))
self.Bind(wx.EVT_CHECKBOX, self.OnCheck)
def OnCheck(self, event):
print "item:", self._ids[event.Id], "checked:", event.Checked()
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.options = HtmlCheckListBox(
self,
[
"<i>one</i>",
"<b>two</b>",
"<u>three</u>"
]
)
app = wx.PySimpleApp()
app.TopWindow = TestFrame()
app.TopWindow.Show()
app.MainLoop()
加载中,请稍侯......
精彩评论