我想用Python編寫一個程序,它可以解決不同的幾何問題,比如計算兩行之間的距離三維座標系統。我正在使用tkinter來創建窗口。不能使用get() - 方法從另一個框架的條目中獲取數據點擊一個按鈕後
下面是一個屏幕截圖,顯示該程序創建窗口:
Screenshot http://oi39.tinypic.com/2iv1wux.jpg
在頂部左側角落(新數據幀)的框架是你選擇那種數據(線條,平面...),您希望爲後續計算添加。通過點擊「weiter」-button(= continue-button),不同的條目被添加到新數據框內的淺灰色框架中。
Screenshot http://oi44.tinypic.com/vemyx1.jpg
然後,您可以添加所有必要的數據。我使用了一個額外的框架,因爲在點擊「hinzufügen」按鈕(= add-data-button)之後,這個額外框架內的所有小部件都被刪除了(我正在使用一個for循環從此框中刪除所有的孩子)。之後,淺灰色框架再次變空,所以您可以添加更多數據。
問題是,當點擊add-data-button(〜hinzufügen)時,它也應該使用命令list.append將所有數據從淺灰色框架中不同的Entry-Widges添加到列表中。隨機的東西」)。我可以訪問列表並添加隨機數據,但我無法使用get() - 方法從淺灰色框架內的Entrys中獲取數據。
下面是一些代碼:
# 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
我如何可以訪問淺灰色框架內從有多種不同的小部件的數據,點擊一個按鈕,這是ouside該框架是什麼時候?
嘗試使用a = entry_Name.get(1.0,END) – user2986701
您的代碼格式不正確 - 縮進不正確。 –
'我不能使用get() - 方法從淺灰色框架內的Entrys獲取數據。「是什麼意思?什麼阻止你使用get方法? –