2014-01-08 2 views
0

몇 가지 체크 박스를 가진 MessageBox를 열어 몇 가지 옵션을 선택하고 싶다. MessageBox는 작동하지만 확인란의 상태에 액세스 할 수 없습니다. 체크 박스 (클래스 작동에 대한 액세스)를 토글 할 수 있지만 상태를 가져올 수 없습니다. 기본 창에서 체크 박스 상태를 다시 얻으려면 어떻게해야합니까? MessageWindow에서 체크 박스 상태를 얻을 수 없다.

프로그램이 작동하는 방법 : 메인 창은 ChooseBox ChooseBox은 (시험 예를 들어, 여기에 하나의 옵션을) 선택할 수있는 옵션을 제공해야 만들 수 있습니다 소바 창 (테스트 버튼으로 여기 테스트) 상태 (python27 작업을 얻을 것이다 창문이 -하지만 우분투에 당신은 두 개의 TK에() 창을 가질 수 없습니다

#!/usr/bin/python3 
# -*- coding: cp1252 -*- 

from Tkinter import * 

class ChooseBox(Tk): 
    def __init__(self): 
     Tk.__init__(self) 

     self.var = IntVar() 
     self.chk = Checkbutton(self, text="Option 1", variable=self.var) 
     self.chk.pack() 
     # Button to show the status of the checkbutton 
     button = Button(self, text='Show Stat', 
          command=lambda: self.Status(self.var)) 
     button.pack() 

    def Status(self, var): 
     print var.get() 

def message(): 
    global Choose 
    Choose = ChooseBox() 
    Choose.mainloop() 

def test(): 
    global Choose 
    Choose.chk.toggle() 
    print Choose.var.get() 

def main_wrapper(argv): 
    global Choose 
    root = Tk() 
    root.geometry("200x150+30+30") 

    Button_Frame=Frame(root) 
    Button_Frame.pack(side=BOTTOM, anchor=W, fill=X, expand=NO) 

    Button(Button_Frame, text='Make ChooseBox', command=message).pack(side=LEFT, anchor=W, padx=5, pady=5) 
    # Button to test access to the Box - here it toggles the Checkbutton and (should) prints the status 
    Button(Button_Frame, text='test', command=test).pack(side=LEFT, anchor=W, padx=5, pady=5) 
    Button(Button_Frame, text='Quit', command=root.quit).pack(side=RIGHT, anchor=E, padx=5) 

    root.mainloop() 


if __name__ == '__main__': 
    main_wrapper(sys.argv) 

답변

1

) 어느 쪽도 작동하지 않았다, TK에 창은 고유 한 번만 호출 할 수 있습니다. 대신 선택 상자에있는 Tk를 Toplevel로 교체하십시오. 그 외에는 잘 작동한다고 생각합니다.

관련 문제