2017-04-25 8 views
-1

これはGUIを備えた温度コンバータです。私はGUIの側面に問題があります。 GUIに追加する前に私のコードが正しく実行されていたので、実際にプログラムを実行すると何も起こりません。 Tkinterファイルが同じフォルダにある可能性があるので、私はそれがわからないのですか?以前にファイルからテキストを取得しているとき、またはGUIが完全に間違ってプログラムされていると、その問題が発生しました。ありがとう!GUIを使用した温度コンバータ

#import 
#main function 
from Tkinter import * 
def main(): 
    root=Tk() 

    root.title("Temperature Converter") 
    root.geometry("400x700") 
    #someothersting="" 
    someotherstring="" 
#enter Celcius 
    L1=Label(root,text="Enter a Celcius temperature.") 
    E1=Entry(root,textvariable=someotherstring) 
    somebutton=Button(root, text="Total", command=lambda: convert(E1.get())) 

    somebutton.pack() 
    E1.pack() 
    L1.pack() 
    root.mainloop()#main loop 


#convert Celcius to Fahrenheit 
def convert(somestring): 
    if somestring != "":  
     # cel=0 dont need these in python 
     # far=0 
     cel=int(somestring) 
     far=(9/5*(cel))+32 
     print(F) 
+0

これはPython 2でもあります。 –

+1

多くの言語で自動的に 'main'が呼び出されますが、Pythonはそれらのどれでもありません。最後に 'main()'を追加してみてください。 – Kevin

答えて

0

mainを追加し、Fをfarに変更します。私はまた、ラベルの状態を変換するための例を追加しました!:)これが役立つことを願っています。

#import 
#main function 
from Tkinter import * 
def main(): 
    root=Tk() 

    root.title("Temperature Converter") 
    root.geometry("400x700") 
    #someothersting="" 
    someotherstring="" 
#enter Celcius 
    L1=Label(root,text="Enter a Celcius temperature.") 
    E1=Entry(root,textvariable=someotherstring) 
    somebutton=Button(root, text="Total", command=lambda: convert(E1.get())) 

    somebutton.pack() 
    E1.pack() 
    L1.pack() 
    root.mainloop()#main loop 


#convert Celcius to Fahrenheit 
def convert(somestring, label): 
    if somestring != "": 
     cel=int(somestring) 
     far=(9/5*(cel))+32 
     answer = str(cel) + " Converted to Farenheit = " + str(far) 
     label.config(text=answer) 

main() 
関連する問題