【问题标题】:TypeError: __init__() takes at least 3 arguments (2 given)TypeError: __init__() 至少需要 3 个参数(给定 2 个)
【发布时间】:2015-11-28 19:33:09
【问题描述】:

我是 Python 面向对象编程的新手所以,我有这个代码:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx, pygame, sys, random, os
from pygame.locals import *
from random import choice
from block import O, I, S, Z, L, J, T

class Example(wx.Frame):


def __init__(self, parent, id, *args, **kwargs):
    super(Example, self).__init__(self, parent, id,*args, **kwargs)  
    self.InitUI()
    image_file = "roses.jpg"
    bmp1 = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.bitmap1 = wx.StaticBitmap(self, -1, bmp1, (0, 0))
[more stuffs...]

并且假设打开一个带有一些按钮的窗口和背景图像。但是当我执行它时,它给了我一个错误:

File "C:\mytetris\aaa.py", line 472, in main
Example(None)
TypeError: __init__() takes at least 3 arguments (2 given)

所以请帮帮我...

【问题讨论】:

  • 缩进不正确。
  • line 472 in main 在哪里?
  • 其实...程序只有471行...

标签: python pygame wxpython


【解决方案1】:

我只能猜测

class Example(wx.Frame):
    def __init__(self, parent, id, *args, **kwargs):

Example 至少需要 3 个参数 selfparentid。对象名称作为 self 传递,因此您必须创建带有 2 个参数的对象 - 例如:

my_example = Example(some_parent, some_id)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 2013-08-15
    • 1970-01-01
    • 2017-06-04
    相关资源
    最近更新 更多