반응형
단일 창을 활용하고 싶을 때,
싱클턴 클래스 작성
class SingletonInstance:
__instance = None
@classmethod
def get_Instance(self):
return self.__instance
@classmethod
def instance(self):
print("instance")
if self.__instance ==None:
self.__instance = self()
else:
self.instance = self.get_Instance
return self.__instance
class ChartWindow(QMainWindow, SingletonInstance):
def __init__(self):
super().__init__()
self.setupUi(self)
self.kiwoom = KiwoomApi()
def __del__(self):
self.__instance = None
싱클턴 클래스를 상속 받아 활용.
self.chart_window = ChartWindow.instance()
반응형
댓글