在第二页不显示小部件?

2024-09-21 09:48:30 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的全部代码:

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级


Tags: youplacelabelareattkspeedelif
1条回答
网友
1楼 · 发布于 2024-09-21 09:48:30

您的代码调用bowlingspeedcalc,它试图创建一些小部件。在下一行中,您有一个从屏幕上删除所有小部件的循环

另外,bowlingspeedcalc的第一行将mEntry的类型与float进行比较,float总是失败的mEntry是一个小部件,而不是一个数字。如果要获取用户输入的数据,必须调用该小部件的get方法。这将始终返回一个字符串,因此需要将其转换为数字

相关问题 更多 >

    热门问题