2017-09-14 6 views
0

레이블을 업데이트하기 위해 주 프레임 새로 고침을 원합니다. MyDialog에서 "완료"단추를 클릭하면 이제는 작동하지 않습니다.자식 대화 상자가 표시 될 때 주 프레임을 새로 고치는 방법

잘못 되었나요? 감사. MyDialog에 : 메인 프레임 메인 프레임의 레이블 업데이트 그것에 버튼이 자식 대화 : 메인 프레임, 내 대화

을 시작하는 그것에 버튼이

코드입니다
# -*- coding: utf-8 -*- 

import wx 

#Dialog 
class MyDialog(wx.Dialog): 
    """setting MyDialog.""" 
    def __init__(self): 
     self.dlg_main = wx.Dialog.__init__(self, None, -1, title="setting", size=(300, 300)) 
     self.btn_ok = wx.Button(self, label="done", pos=(30, 30), size=(50, 26)) 
     self.Bind(wx.EVT_BUTTON, self.__OnButtonClick_save, self.btn_ok,) 

    def __OnButtonClick_save(self, event): 
     self.Destroy() 
     main = MainFrame() 
     **main.set_label_name('test')** 
     main.Destroy() 

def start_dialog(): 
    my_dialog = MyDialog() 
    my_dialog.ShowModal() 
    my_dialog.Destroy() 

#Main Frame 
class MainFrame(wx.Frame): 
    def __init__(self): 
     self.main_frame = wx.Frame.__init__(self, None, -1, title='simple', size=(400, 400)) 
     self.Centre() 
     self.label_name = wx.StaticText(self, label="Hello,everyone", pos=(30, 30)) 
     self.btn_set = wx.Button(self, label="set", pos=(30, 60)) 
     self.Bind(wx.EVT_BUTTON, self.on_button_click, self.btn_set) 

    def set_label_name(self, str): 
     print(str) 
     self.label_name.SetLabel('hello, Boys') 

    def on_button_click(self, event): 
     start_dialog() 

def show_main(): 
    main = wx.App() 
    main_win = MainFrame() 
    main_win.Show() 
    main.MainLoop() 

if __name__ == '__main__': 
    show_main() 

답변

0

나는이 방법을 가지고있다, 모두에게 감사한다!

포인트는 부모 메소드를 호출하는 방법이므로 self.parent.xxx를 사용하여 문제를 해결하십시오. 이 같은

코드 :이 답변의 아이디어

# -*- coding: utf-8 -*- 

import wx 

#Dialog 
class MyDialog(wx.Dialog): 
    """setting MyDialog.""" 
    def __init__(self, parent, title): 
     super(MyDialog, self).__init__(parent, title=title, size=(300, 300)) 
     self.parent = parent 
     panel = wx.Panel(self) 
     btn_ok = wx.Button(panel, label="done", pos=(30, 30), size=(50, 26)) 
     btn_ok.Bind(wx.EVT_BUTTON, self.__OnButtonClick_save) 

    def __OnButtonClick_save(self, event): 
     #THis is the different 
     self.parent.set_label_name('test') 
     self.Destroy() 

def start_dialog(): 
    my_dialog = MyDialog() 
    my_dialog.ShowModal() 
    my_dialog.Destroy() 

#Main Frame 
class MainFrame(wx.Frame): 
    def __init__(self): 
     self.main_frame = wx.Frame.__init__(self, None, -1, title='simple', size=(400, 400)) 
     self.init_ui() 

    def init_ui(self): 
     self.label_name = wx.StaticText(self, label="Hello,everyone", pos=(30, 30)) 
     btn_set = wx.Button(self, label="set", pos=(30, 60)) 
     btn_set.Bind(wx.EVT_BUTTON, self.on_button_click) 
     self.Centre() 

    def set_label_name(self, str): 
     self.label_name.SetLabel('hello, Boys') 

    def on_button_click(self, event): 
     my_dialog = MyDialog(self, "setting") 
     my_dialog.ShowModal() 
     my_dialog.Destroy() 

def show_main(): 
    main = wx.App() 
    main_win = MainFrame() 
    main_win.Show() 
    main.MainLoop() 

if __name__ == '__main__': 
    show_main() 

감사 Wxpython show dialog on main frame startup