0

これは私のコード全体です:

import sys
import tkinter as tk
import os

def bowlingspeedcalc ():
    if type(mEntry) == float:
        speed = 0.01890*3600/mEntry

        if speed >165:
            tk.Label (str(speed) + " kph !!! You don't bowl that fast!!!o_0 ").place (x = 50,y = 50)                             

        elif speed >=140:
            tk.Label ("You are a fast bowler,you bowl at: " + str(speed) + " kilometers per hour").place (x = 50,y = 50) 

        elif speed >= 130:
            tk.Label ("You are a fast-medium bowler,you bowl at: " + str(speed) + " kilometers per hour").place (x = 50,y = 50)

        elif speed >= 120:
            tk.Label ("You are a medium-fast bowler,you bowl at: " + str(speed) + " kilometers per hour").place (x = 50,y = 50)

        elif speed >= 105:
            tk.Label ("You are a medium pace bowler,you bowl at: " + str(speed) + " kilometers per hour").place (x = 50,y = 50)

        elif speed < 105 and speed > 60:
            tk.Label ("You are a spin bowler,you bowl at: " + str(speed) + " kilometers per hour").place (x = 50,y = 50)

        elif speed <= 60:
            tk.Label ("You bowl at: " + str(speed) + " kilometers per hour; you bowl like my grandma!!!").place (x = 50,y = 50)





def forget_page ():
    widgets = [mlabel1,mlabel2,mlabel3,mEntry,mButton]
    bowlingspeedcalc ()
    for widget in widgets:
        widget.place_forget ()

mGui = tk.Tk()
mGui.geometry("300x300")
mGui.title("YourBowlingSpeed")
mlabel1 = tk.Label (text = "How much time does your ball take to cover the")
mlabel2 = tk.Label (text = "20m/22yrds ,from the release to crossing ")
mlabel3 = tk.Label (text = "the stumps?")
mlabel1.place (x = 20,y = 5)
mlabel2.place (x = 17,y = 22)
mlabel3.place (x = 130,y = 39)
mEntry = tk.Entry()
mEntry.place (x = 115,y = 56)
mButton = tk.Button (text = "Calculate",command = forget_page)
mButton.place (x = 125, y = 73)

これが私のコードのすべてです... mbuttonのコマンドはforget_pageどちらに行くのbowlingspeedcalcですが、プログラムが実行されると、新しいページに何も表示されませんか??? 任意の助けをいただければ幸いです.... :D

4

1 に答える 1

0

あなたのコードはbowlingspeedcalc、いくつかのウィジェットを作成しようとする を呼び出します。次の行には、画面からすべてのウィジェットを削除するループがあります。

また、 の最初の行はの型を floatbowlingspeedcalcと比較しますが、これは常に失敗します。数字ではなくウィジェットです。ユーザーが入力したデータを取得する場合は、そのウィジェットのメソッドを呼び出す必要があります。これは常に文字列を返すため、数値に変換する必要があります。mEntrymEntryget

于 2013-08-22T12:31:26.030 に答える