断言错误WxPython [英] Assertion Error WxPython

查看:203
本文介绍了断言错误WxPython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

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()

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 <module>
    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

如代码中所述,它将成为一个媒体共享平台.
当我调用.Bind时,似乎发生了一些可疑的事情.
有人可以帮帮我,cl一下这里发生的事情吗?
谢谢.

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.

推荐答案

原来我犯了一个菜鸟错误
override_contents中,我传递了一个字符串而不是代码.
我要做的就是:

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.

这篇关于断言错误WxPython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆