2017-12-25 2 views
0

파이썬에서 wxWidgets의 그래픽 요소 값을 저장하고 복원하는 방법은 무엇입니까? 좀 더 친근한 방법을 원합니다. 아마도 for을 사용하여 모든 요소를 ​​긁어 내고 창을 닫고 앱을로드 할 때 복원 할 때 txt에 현재 값을 저장하십시오. 내가 추가하는 각각의 새로운 요소에 2 줄의 코드 (저장 및 복원)를 입력하고 싶지 않습니다.wxWidgets 파이썬은 체크 박스와 다른 요소 값을 텍스트에 저장합니다

+0

{wx} python의 어떤 버전을 사용하십니까? os/toolkit은 무엇입니까? – Igor

+0

wxWidets = 4.0.0a3 gtk2 (phoenix), 우분투의 python 3 16.04 – hildogjr

+0

참고 자료를 보려면 http://docs.wxwidgets.org/trunk/classwx_config_base.html을 참조하십시오. – Igor

답변

0

@Igor, 사용 팁 덕분에 config_base.

configHandle = wx.Config(CONFIG_FILE) 
# Sweep all elements in `self()` to find the grafical ones 
# instance of the wxPython and salve the specific configuration. 
for wxElement_name, wxElement_handle in self.__dict__.items(): 
    # Each wxPython object have a specific parameter value 
    # to be saved and restored in the software initialization. 
    if isinstance(wxElement_handle, wx._core.TextCtrl): 
     configHandle.Write(wxElement_name, wxElement_handle.GetValue()) 
    elif isinstance(wxElement_handle, wx._core.CheckBox): 
     configHandle.Write(wxElement_name, ('True' if wxElement_handle.GetValue() else 'False')) 
    elif isinstance(wxElement_handle, wx._core.SpinCtrl): 
     configHandle.Write(wxElement_name, str(wxElement_handle.GetValue())) 
    . 
    . 
    . 

는이 코드의 반대 논리를 사용하여 복원하려면 : 나는 기반으로이 코드를 만들었습니다.

관련 문제