From the system import Windows
The class messagebox (Windows. Windows) :
Def __init__ (self, screen, the message) :
The self. The screen=screen
The self. The message=message
Self. Position_h=200
Self. Position_w=300
Self. Havecontrol=True
Self. Canbemax=False
Self. Canbemin=False
Self. Recount ()
Def Show (self) :
Super (). The Show ((179217217))
/system/Windows. Py
The import pygame
From the system import screenos
The from pygame. Locals import *
The class Windows (object) :
Window class system at "'" '
Def __init__ (self) :
Pygame. The init ()
The self. The screen=None
Self. Position_h=800
Self. Position_w=600
Self. Position_y=int (screenos. Screen () screen_h/2 - self. Position_h/2)
Self. Position_x=int (screenos. Screen () screen_w/2 - self. Position_w/2)
Self. Canbemin=True
Self. Canbemax=True
Self. Havecontrol=True
Self. Control_w=20
Self. Alwaystop=False
# todo
Def Show (self, color) :
Pygame. The draw. The rect (self. Screen, (0, 0), (self. Position_x, self position_y, self. Position_w, self. Position_h), 0)
If self. Havecontrol:
Pygame. The draw. The rect (self) screen, color, (self. Position_x + 1, self position_y + self. Control_w,
Self. Position_w - 2, the self. The position_h - 2), 0)
The else:
Pygame. The draw. The rect (self) screen, color,
(self. Position_x + 1, self position_y + 1, the self. The position_w - 2, the self. The position_h - 2), 0)
# todo
As title, a messagebox using super Show calls the superclass Windows Show, the result error:
AttributeError: 'messagebox object has no attribute' control_w,
Windows in the class has a self control_w but he said no, but if I am in a messagebox assignment again, he will be identified,
CodePudding user response:
- the problem resolved -Himself over the textbooks: call in the derived class __init (after) will not automatically calls the superclass __init (),
CodePudding user response:
Wrong number, is __init__ ()