wxpython应用程序错误,断言错误WxPython

I have this code:

import wx

class application(wx.Frame):

def __init__(self, *args, **kw):

super(application, self).__init__(*args, **kw)

panel = wx.Panel(self)

# Header

Header = wx.StaticText(panel, label="Browse", pos=(25, 25))

HeaderFont = Header.GetFont()

HeaderFont.PointSize += 10

HeaderFont = HeaderFont.Bold()

Header.SetFont(HeaderFont)

# displaying everything in 'override_contents.py'

from override_contents import contents

posx = 25

posy = 60

change = 0

def contentButtonDisplay(panel=panel, id=wx.ID_ANY, label="None", pos=(0,0), event=None, i=None):

wx.Button(panel, id, label, pos).Bind(wx.EVT_BUTTON, event)

for i in contents:

contentButtonDisplay(label=i["name"], pos=(posx, posy), event=i["event"])

if change == 5:

posy += 50

posx = 0

change = 0

else:

posx += len(i) * 10

change += 1

app = wx.App()

frm = application(None, title='Browse')

frm.Show()

app.MainLoop()

And override_contents:

contents=[

{

"name" : "PyGame",

"event": "print('Hello!')"

}

]

When I run it I get

Traceback (most recent call last):

File "C:/Users/???'s Coding/PycharmProjects/Interface/browse.py", line 32, in

frm = application(None, title='Browse')

File "C:/Users/???'s Coding/PycharmProjects/Interface/browse.py", line 22, in __init__

contentButtonDisplay(label=i["name"], pos=(posx, posy), event=i["event"])

File "C:/Users/???'s Coding/PycharmProjects/Interface/browse.py", line 20, in contentButtonDisplay

i.Bind(wx.EVT_BUTTON, event)

File "C:\Users\???'s Coding\Desktop\Python Intall Directory\lib\site-packages\wx\core.py", line 1350, in _EvtHandler_Bind

assert callable(handler) or handler is None

AssertionError

As stated in the code, it is going to be a media sharing platform.

It seems that something shady is going on when I call to .Bind.

Can someone please help me and clariafy what is going on here?

Thanks.

解决方案

Turns out I made a rookie mistake

In override_contents I passed a string instead of code.

All I had to do was:

import wx

def onPygame():

wx.MessageBox("Pygame!", "Pygame!")

# ...

"event": lambda _: onPygame

# ...

So, yeah. Rookie mistake.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值