[Tutor] Multiple inheritance - almost correct, I think

Phil phillor9 at gmail.com
Fri May 14 05:53:47 EDT 2021


On 14/5/21 5:04 pm, Cameron Simpson wrote:

A cut and copy from VS Code instead of IDLE.

Traceback (most recent call last):
   File "/home/phil/Python/wxpython_meter_test.py", line 83, in <module>
     frame = MyForm().Show()
   File "/home/phil/Python/wxpython_meter_test.py", line 19, in __init__
     Meter.__init__(self, Meter.start_x)
AttributeError: type object 'Meter' has no attribute 'start_x'

Line 19 is:
Meter.__init__(self, Meter.start_x)

This now appears to be the only error.

importwx
importmath
classMeter:
def__init__(self, start_x):
self.angle= 180# start with the pointer pointing to the left
self.rad= 0
self.start_x= start_x# the starting point of the pointer
self.start_y= 200
self.length= 50# the length of the pointer
self.inc_amount= 5
classMyForm(wx.Frame, Meter):
def__init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Meter Test", size=(300, 300))
Meter.__init__(self, Meter.start_x)
#m = Meter(200)
#print(m.angle)
'''
These variables have been moved to the meter class
self.angle = 180 # start with the pointer pointing to the left
self.rad = 0
self.start_x = 200 # the starting point of the pointer
self.start_y = 200
self.length = 50 # the length of the pointer
self.inc_amount = 5
'''
self.InitUI()
defInitUI(self):
self.Bind(wx.EVT_PAINT, self.OnPaint)
panel= wx.Panel(self, wx.ID_ANY)
self.timer= wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.timer.Start(100)
defupdate(self, event):
#m = Meter(200) # m.self.angle etc is not correct here
ifMeter.angle== 360:
Meter.inc_amount*= -1
Meter.angle+= Meter.inc_amount
ifself.angle== 180:
Meter.inc_amount*= -1
Meter.rad= (Meter.angle* math.pi/ 180)
self.Refresh()
defOnPaint(self, e):
dc= wx.PaintDC(self)
# Create graphics context
gc= wx.GraphicsContext.Create(dc)
ifgc:
gc.SetPen(wx.RED_PEN)
path= gc.CreatePath()
path.AddArc(Meter.start_x, Meter.start_y, 60, math.radians(180),
math.radians(0), 1)
path.AddLineToPoint(140, self.start_y)
#gc.StrokePath(path)
gc.DrawPath(path)
x= int(Meter.start_x+ math.cos(Meter.rad) * Meter.length)
y= int(Meter.start_y+ math.sin(Meter.rad) * Meter.length)
dc.DrawLine(Meter.start_x, Meter.start_y, x, y)
if__name__== "__main__":
app= wx.App()
frame= MyForm().Show()
app.MainLoop()

-- 
Regards,
Phil



More information about the Tutor mailing list