2017-11-18 29 views
-3

如何提取變量的數字變量,到後來進行計算與: 例如Tkinter的進入,如何利用已經使用

from tkinter import * 
import math 
root = Tk() 
root.mainloop() 
# ............ 
entry1 = Entry(root) 
entry2 = Entry(root) 
def sum(): 
    puhs = math.sqrt(enttry1.get()/entry2.get()) 
    rel = Label(root,text=puhs) 
    rel.pack() 
    #---the problem 
    rad2 = (entry1*puhs) # this is where I get the error 
    rel2 = Label(root, text=rad2) 
    rel2.pack() 

calc = Button(root, text="pulse", command= sum) 
calc.pack() 
rpta = Label(root, text="puhs") 
rpta.pack() 

我的問題是,我該如何使用變量「推「用它來創造更多的計算?

+0

你的意思是'不puhs''push'我猜?在你的代碼中似乎一致是一個錯字。 – roganjosh

回答

0

我不認爲你甚至跑過你發佈的代碼; mainloop()位於錯誤的地方,並且在變量名稱中存在拼寫錯誤。

大多數情況下,你必須pack()輸入字段,你必須從輸入字段獲得的值轉換成數值(在這裏漂浮)

from tkinter import * 
import math 
root = Tk() 
# ............ 
entry1 = Entry(root) 
entry2 = Entry(root) 
entry1.pack() 
entry2.pack() 

def sum(): 
    puhs = math.sqrt(float(entry1.get())/float(entry2.get())) 
    rel = Label(root,text=puhs) 
    rel.pack() 
    #---the problem 
    rad2 = float(entry1.get()) * puhs # this is where I get the error 
    rel2 = Label(root, text=rad2) 
    rel2.pack() 

calc = Button(root, text="pulse", command= sum) 
calc.pack() 
rpta = Label(root, text="puhs") 
rpta.pack() 

root.mainloop() 
+0

我的錯誤,請原諒我 – royer

+0

很高興我能幫忙;如果它適合你,請參閱https://stackoverflow.com/help/someone-answers –