2013-08-21 53 views
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) 

這是allof我的代碼...一個mbutton的命令去forget_page都到bowlingspeedcalc但在執行程序不列入它顯示新頁面上的任何內容? ??任何幫助,將不勝感激....:D

+1

我們不可能猜出爲什麼你的代碼有bug,沒有看到可重複的情況。至少,我們需要查看你定義的'mlabel','mlabel2'等,以及創建第二頁的代碼。 –

回答

0

您的代碼調用bowlingspeedcalc,它試圖創建一些小部件。在下一行中,您有一個循環來從屏幕中刪除所有的小部件。

此外,bowlingspeedcalc的第一行將mEntry的類型與float相比較,這將始終失敗。 mEntry是一個小部件,而不是一個數字。如果您想獲取用戶輸入的數據,則必須調用該小部件的get方法。這將始終返回一個字符串,因此您需要將其轉換爲數字。

+0

謝謝,因爲我是python新手,我可以在哪裏找到「get」方法? –

+0

@ShahidIqbal:它可能在與tkinter Entry小部件相關的每個教程和文檔中都有提及。這裏有一個:http://effbot.org/tkinterbook/entry.htm#Tkinter.Entry.get-method –

+0

是的,但get方法是獲取字符串值,所以你知道從輸入框中檢索FLOAT vales的方法嗎? –