2013-12-12 1 views
-1

파이썬에서 서로 다른 기하학적 문제를 해결할 수있는 프로그램을 작성하려고합니다. 3D 좌표계. 창을 만들려면 tkinter를 사용하고 있습니다. 당신은 데이터의 종류를 선택하는 경우버튼을 클릭 한 후 get() - 메서드를 사용하여 다른 프레임의 항목에서 데이터를 가져올 수 없습니다.

Screenshot http://oi39.tinypic.com/2iv1wux.jpg

상단 좌측 코너 (새로운 데이터 프레임)의 프레임은 다음과 같습니다

프로그램이 생성되는 창을 보여주는 스크린 샷입니다 (선,면 ...)을 계산할 수 있습니다. "weiter"-buttton (= 계속 버튼)을 클릭하면 새 데이터 프레임 안의 밝은 회색 프레임에 다른 항목이 추가됩니다.

Screenshot http://oi44.tinypic.com/vemyx1.jpg

당신은 모든 필요한 데이터를 추가 할 수 있습니다.

"hinzufügen"버튼 (= add-data-button)을 클릭하면이 추가 프레임 안의 모든 위젯이 삭제됩니다 (for-loop를 사용하고 있기 때문에). 이 프레임에서 모든 하위 항목을 삭제합니다). 그 후 밝은 회색 프레임이 다시 비어있어 더 많은 데이터를 추가 할 수 있습니다.

add-data-button (~ hinzufügen)을 클릭 할 때 문제는 밝은 회색 프레임의 다른 항목 Widges의 모든 데이터를 list.append (" 랜덤 한 것"). 목록에 액세스하고 임의의 데이터를 추가 할 수 있지만 get() - 메서드를 사용하여 밝은 회색 프레임 안의 항목에서 데이터를 가져올 수 없습니다.

# this is the function that creates the entries in the light grey frame 
# the continuebutton (~weiter) is using this method after you click it 
# li_datatype is the list where you can choose what kind of data to add. 
# as you can see, it contains four elements. 
# depending on the chosen elements, a certain amount of entries is created 
# in the light grey frame 

def data_input(): 
if li_datatype.get("active") == "Punkt": 
     add.append(["DATATYPE","NAME","X","Y","Z"]) 
     #name 
     lbl_text_1 = Label(f_input_2, text="Name des Punktes:", bg="#f8f8f8") 
     lbl_text_1.place(relx=0.02, rely=0.1, anchor="w") 
     entry_Name = Entry(f_input_2) 
     entry_Name.place(relx=0.98, rely=0.1, anchor="e", width="110") 

     #Info 
     lbl_text_2 = Label(f_input_2, text="P(X/Y/Z)", bg="#f8f8f8") 
     lbl_text_2.place(relx=0.02, rely=0.3, anchor="w") 

     #Eingabe Punkt 
     lbl_text_2 = Label(f_input_2, text="Punkt:", bg="#f8f8f8") 
     lbl_text_2.place(relx=0.02, rely=0.45, anchor="w") 

     lbl_X = Label(f_input_2, text="X:",font="8", bg="#f8f8f8") 
     lbl_Y = Label(f_input_2, text="Y:",font="8", bg="#f8f8f8") 
     lbl_Z = Label(f_input_2, text="Z:",font="8", bg="#f8f8f8") 
     lbl_X.place(relx=0.02,rely=0.6,anchor="w") 
     lbl_Y.place(relx=0.35,rely=0.6,anchor="w") 
     lbl_Z.place(relx=0.67,rely=0.6,anchor="w") 

     entry_X = Entry(f_input_2) 
     entry_Y = Entry(f_input_2) 
     entry_Z = Entry(f_input_2) 
     entry_X.place(relx=0.13,rely=0.6,anchor="w", width="35") 
     entry_Y.place(relx=0.46,rely=0.6,anchor="w", width="35") 
     entry_Z.place(relx=0.78,rely=0.6,anchor="w", width="35") 
elif (...) 
# the other code basically does the same thing 

# this is what happens after you click the "add-data-button" (~hinzufügen) 

def data_add(): 
    a = entry_Name.get() 
    print(a) 

    for child in f_input_2.winfo_children(): 
     child.destroy() 

# i first tried to save the info from the name-entry inside a variable, but it doesn't work 

가 어떻게 빛 회색 프레임 내부의 diffrent 위젯의 데이터에 액세스 할 수 있습니다, 그 프레임 ouside의 버튼을 클릭하면 다음과 같습니다

코드의 일부인가?

+0

= entry_Name.get (1.0, END) – user2986701

+0

코드를 잘못 입력했습니다. 들여 쓰기가 잘못되었습니다. –

+0

''get() - 메서드를 사용하여 밝은 회색 프레임 안의 항목에서 데이터를 가져올 수 없습니까? ' 무엇이 get 메소드를 사용하지 못하게합니까? –

답변

0

코드에서 로컬 변수를 사용하여 위젯에 대한 참조를 저장하고 있습니다. 당신이 중 하나를 수행해야 다음 인스턴스가 전역 변수로

  • 저장을 참조를 속성으로 객체 지향 접근 방식에

    • 스위치는
    • 은 버튼의 패스를 가지고있는 위젯에 대한 참조를 저장할 수 있도록 위젯을 콜백으로 참조하는 것입니다 (버튼이 동일한 범위에서 생성되었다고 가정).

    아무 것도 tkinter에만 고유합니다. 요컨대, 객체로부터 값을 얻으려면 객체에 대한 참조가 있어야합니다. 이러한 작업을 수행하는 데는 여러 가지 방법이 있습니다.

  • 관련 문제