在wx.ToolBar中绘制奇怪的wx.CheckBox

时间:2011-11-29 01:12:01

标签: checkbox wxpython

这是我的工具栏的代码:

JS_TOOLBAR_BUTTON = 0
JS_TOOLBAR_SEPARATOR = 1
JS_TOOLBAR_MONTHCONTROL = 2
JS_TOOLBAR_CHECKBOX = 3

def createToolbar(self):
    self.tb = wx.ToolBar(self, style=wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT) 
    self.tb.SetToolBitmapSize((16,16))         
    id=0 
    for toolType,hint,pic,proc in self.toolbarData():
        if toolType==JS_TOOLBAR_BUTTON: 
            id += 10
            self.tb.AddLabelTool(id, hint, pic.GetBitmap(), shortHelp=hint)
            self.Bind(wx.EVT_TOOL, proc, id=id)
            self.Bind(wx.EVT_TOOL_RCLICKED, proc, id=id)  
        elif toolType==JS_TOOLBAR_SEPARATOR: 
            self.tb.AddSeparator()
        elif toolType==JS_TOOLBAR_CHECKBOX:        
            self.tb.AddControl(wx.CheckBox(self.tb, label=hint))

    self.tb.Realize()       
def toolbarData(self):
    return((JS_TOOLBAR_BUTTON, u"Добавить работника", pictures.add_staff, self.grid.on_insert),                 
           (JS_TOOLBAR_BUTTON, u"Удалить работника",  pictures.del_staff, self.grid.on_delete),        
           (JS_TOOLBAR_SEPARATOR, None,  None, None),
           (JS_TOOLBAR_CHECKBOX, u"Показывать только работающих", None, self.grid.on_delete))

结果我在复选框外面有一些奇怪的角:

Image

Python 2.7,wx-2.9.2,在Win7x64下

1 个答案:

答案 0 :(得分:1)

我的解决方案是使用CheckLabelTool而不是CheckBox:

enter image description here

self.tb.AddCheckLabelTool(id, hint, pic.GetBitmap(), shortHelp=hint)                
self.tb.ToggleTool(id, self.grid.Table.actualOnly) 
self.Bind(wx.EVT_TOOL, proc, id=id)