Hi, all
from threading import Thread
import wx
class MainWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="sylphlker")
self.Center()
self.panel = wx.Panel(self, wx.ID_ANY)
self.k1 = wx.TextCtrl(self.panel, -1, "F1", size=(45,25), style=wx.TE_READONLY)
def HotKey():
hotkey = MainWindow.k1.GetValue()
print(hotkey)
if __name__ == '__main__':
app = wx.App()
frame = MainWindow()
frame.Show()
app.MainLoop()
p = Thread(target=HotKey, daemon=True)
p.start()
p.join()
Exception in thread Thread-1:
Traceback (most recent call last):
File âC:\Python37\lib\threading.pyâ, line 926, in _bootstrap_inner
self.run()
File âC:\Python37\lib\threading.pyâ, line 870, in run
self._target(*self._args, **self._kwargs)
File âtest3.pyâ, line 15, in HotKey
hotkey = MainWindow.k1.GetValue()
AttributeError: type object âMainWindowâ has no attribute âk1â
Why does this happen? How to reference attributes of other classes?