简体   繁体   中英

CheckBox Event in wxPython not working

I'm sorry if this is so simple, but I'm trying to bind an event to a checkbox in a menubar with wxPython. For some reason, it won't work! I've tried a variety of different ways to get it to print a statement, but nothing happens when I check the box. Is it not binding correctly? This is just a simple app I wrote to demonstrate the problem...

import wx

class Frame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        panel = wx.Panel(self)

        menuBar = wx.MenuBar()

        menu = wx.Menu()

        self.checkbox = menu.AppendCheckItem(-1, "Check me")

        menuBar.Append(menu,'&check box')

        self.SetMenuBar(menuBar)

        self.Bind(wx.EVT_CHECKBOX, self.onCheck, self.checkbox)

    def onCheck(self, e):
        print self.checkbox.IsChecked()

app = wx.App()
test = Frame(None, -1, "Test")
test.Show()
app.MainLoop()

I've figured it out. I needed to change the Bind event from wx.EVT_CHECKBOX to wx.EVT_MENU .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM