IF KeyPressed THEN DrawSomething OR How to connect Events

Hi,

my program waits till a key is pressed and should then just draw a line. But I get an AttributeError: MyProgram instance has no attribute 'Connect'

code:

import wx

class MyProgram:
  def __init__(self, panel):
    panel.Bind(wx.EVT_CHAR, self.LogKeyEvent)
    
  def LogKeyEvent(self, evt):
    wx.EVT_PAINT(self, self.OnPaint)
    
  def OnPaint(self, event=None):
    dc = wx.PaintDC(self)
    dc.Clear()
    dc.SetPen(wx.Pen("RED", 4))
    dc.DrawLine(0, 0, 10, 10)
    
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Test")
panel = wx.Panel(frame)
MyProgram(panel)
frame.Show(True)
app.MainLoop()

Regards,
Franz