gui - wxpython中,怎样创建可以绑定单击事件的一级菜单?
怪我咯
怪我咯 2017-04-17 11:41:53
0
1
787

如题,尝试在一级菜单中绑定单机事件,但无论如何尝试都以失败告终.

发现在菜单追加的二级菜单是可以正常绑定事件的,但是一级菜单wx.Menu即使是绑定wx.EVTMENUOPEN事件也会导致无法显示,求解决!

编译环境:Eclipse+Pydev+Python2.7

我的代码如下,虽然编译通过了,但是无法正常显示:

#-*- coding: utf-8 -*-
import wx

class App(wx.App):
    def OnInit(self):
        self.frame = rpFrame(parent=None, id=-1)
        self.frame.Show()
        self.SetTopWindow(self.frame)

        return True

class rFrame(wx.Frame):
    def __init__(self, parent=None, id=-1):
        wx.Frame.__init__(self, parent, id,'标题')
#状态栏
        statusBar = self.CreateStatusBar() 
#菜单栏
        menuBar = wx.MenuBar()
        self.SetMenuBar(menuBar)
#菜单
        menu1 = wx.Menu()
        menuBar.Append(menu1, "文件")
        menu2 = wx.Menu()
        menuBar.Append(menu2, "退出")
#绑定事件
        self.Bind(wx.EVT_MENU, self.OnCloseMe, menu1)

    def OnCloseMe(self, event):
        self.Close(True)

if __name__ == '__main__':
    app = App()
    app.MainLoop()
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
PHPzhong

The modified program still cannot run and there is an error.

Traceback (most recent call last):
  File "test.py", line 32, in <module>
    app = App()
  File "/usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2/wx/_core.py", line 8631, in __init__
    self._BootstrapApp()
  File "/usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2/wx/_core.py", line 8196, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "test.py", line 6, in OnInit
    self.frame = rFrame(parent=None, id=-1)
  File "test.py", line 26, in __init__
    self.Bind(wx.EVT_MENU, self.OnCloseMe, menu1)
  File "/usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2/wx/_core.py", line 4225, in Bind
    assert source is None or hasattr(source, 'GetId')
AssertionError

There may be a problem with your Bind usage.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!