2012-10-11 2 views
0


Tkinter GUI가있는이 Python 프로그램의 "BackButton"에 몇 가지 문제가 있습니다. MainFrame은 동적 컨텐츠가 포함 된 프레임입니다.
두 메뉴 포인트 (장치 구성 및 SCPI 명령)에서 이전 Frame/Window (이 경우 MainFrame/MainMenu)로 돌아 오는 BackButton을 구현하고 싶습니다. 저는 SCPIMenu의 마스터 Frame과 약간 혼동되어 있습니다, 여기서 '???'를 입력했습니다.
구현 방법이 있습니까? 시간 내 줘서 고마워.BackButton이 MainMenu 인 Tkinter 프레임

class View(Tk): 
    def __init__(self): 
     Tk.__init__(self) 
     self.title('Device Configurator') 
     self.geometry('400x400') 
     self.resizable(0,0) 

     self.MainFrame = Frame(self, bd = '2', relief = RIDGE) 
     self.MainFrame.pack(expand = True, fill="both", padx = 5, pady = 20) 

     menubar = Menu(self) 
     filemenu = Menu(menubar, tearoff=0) 
     filemenu.add_command(label='Configure Devices', command = None) 
     filemenu.add_command(label='Exit', command=self.quit) 
     menubar.add_cascade(label='File', menu=filemenu) 
     infomenu = Menu(menubar, tearoff = 0) 
     infomenu.add_command(label='About', command = None) 
     menubar.add_cascade(label='Info', menu = infomenu) 
     self.config(menu = menubar) 

    def mainMenu(self): 
     configButton = Button(self.MainFrame, text = 'Device Configuration') 
     configButton.place(x=200, y=150,anchor=CENTER) 

     SCPIButton = Button(self.MainFrame, text = 'SCPI Command', command = self.SCPIMenu) 
     SCPIButton.place(x=200, y=200,anchor=CENTER) 

    def SCPIMenu(self): 
     self.SCPIFrame = Frame(???, bd = '2', relief = RIDGE) 
     self.SCPIFrame.pack(expand = True, fill="both", padx = 5, pady = 20) 
     BackButton = Button(???, text = 'Back', command = self.mainMenu) 
     BackButton.place(x=350, y=330, anchor=CENTER) 






##The controller understands both the model and the view. 
class Controller(object): 
    def __init__(self): 
     self.view = View() 
     self.view.mainMenu() 
     self.view.mainloop() 


c = Controller() 
+0

위젯을 숨길 때이 질문을 볼 수 있습니다 (http://stackoverflow.com/q/3819354). 화면을 그리는 방법으로 화면을 보거나 (이전에 그곳에 있었던 것을 제거하는) 화면을 선택하거나, 처음에 채우고 표시하거나 숨길 수있는 '프레임'으로 선택할 수 있습니다. 나중에 내 선호도가있다. (절차적인 방식보다는 GUI/상태 지향적이며 의존성을 제한 할 수있다.) – FabienAndre

+0

처음 "SCPI 명령"버튼을 누르면 무엇을하고 싶습니까? 창의 전체 내용이 SCPIMenu 프레임으로 대체되기를 원하십니까? 아니면 별도의 팝업 창에서 프레임을 원합니까? –

+0

SCPIMenu 프레임으로 대체 된 창 전체 내용을 원하고 뒤로 단추를 클릭하면 MainFrame으로 돌아가고 싶습니다. – eljobso

답변

0

나는 당신이 당신의 초기 프레임을 생성하고 초기화 (자기) 당신을 호출하는 방법을 만들 제안합니다.

그런 식으로, 당신은 당신의 단추에는 mainMenu 명령 youe를 호출 할 때, 당신의 프레임은 원래 설정으로 재설정됩니다

난 그냥 코드를 재사용하고 havent 한 그것을 시도, 당신의 방법을 repasted,하지만 당신은 할 수 shoudl 비슷한 것을하려고

def mainMenu(self): 

    self.MainFrame = Frame(self, bd = '2', relief = RIDGE) 
    self.MainFrame.pack(expand = True, fill="both", padx = 5, pady = 20 

    configButton = Button(self.MainFrame, text = 'Device Configuration') 
    configButton.place(x=200, y=150,anchor=CENTER) 

    SCPIButton = Button(self.MainFrame, text = 'SCPI Command', command = self.SCPIMenu) 
    SCPIButton.place(x=200, y=200,anchor=CENTER) 
    self.MainFrame = Frame(self, bd = '2', relief = RIDGE) 
    self.MainFrame.pack(expand = True, fill="both", padx = 5, pady = 20) 
관련 문제