Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 销毁现有标签_Python_Tkinter - Fatal编程技术网

Python 销毁现有标签

Python 销毁现有标签,python,tkinter,Python,Tkinter,我试图使用python中的Tkinter在UI中运行多个计算,其中必须显示所有计算的所有输出。问题是,第一次计算的输出很好,但进一步计算的输出似乎是根据默认值计算出来的。我开始知道我应该销毁第一个标签,以便输出第二个计算结果,但当我试图销毁第一个标签时,我做不到。我试过的代码如下: from tkinter import * def funcname(): #My calculations GMT = GMT_user.get() lat = lat_deg_user.get()

我试图使用python中的Tkinter在UI中运行多个计算,其中必须显示所有计算的所有输出。问题是,第一次计算的输出很好,但进一步计算的输出似乎是根据默认值计算出来的。我开始知道我应该销毁第一个标签,以便输出第二个计算结果,但当我试图销毁第一个标签时,我做不到。我试过的代码如下:

from tkinter import *

def funcname():
#My calculations
   GMT = GMT_user.get()
   lat = lat_deg_user.get()

   E = GMT * 365
   Eqntime_label.configure(text=E)


   Elevation = E/lat
   Elevation_label.configure(text=Elevation)

nUI_pgm = Tk()
GMT_user = DoubleVar()
lat_deg_user = DoubleVar()

nlabel_time = Label(text = "Enter time in accordance to GMT in decimal").pack()
nEntry_time = Entry(nUI_pgm, textvariable = GMT_user).pack()

nlabel_Long = Label(text = "Enter Longitude in Decimal Degrees").pack()
nEntry_Long = Entry(nUI_pgm, textvariable = lat_deg_user).pack()

nbutton = Button(nUI_pgm, text = "Calculate", command = funcname).pack()


#Displaying results

nlabel_E = Label (text = "The Equation of Time is").pack()
Eqntime_label = Label(nUI_pgm, text="")
Eqntime_label.pack()
#when i try
Eqntime_label.destroy() # this doesn't work

nlabel_Elevation = Label(text = "The Elevation of the sun is").pack()
Elevation_label = Label(nUI_pgm, text="")
Elevation_label.pack()

nUI_pgm.mainloop() 

在这里,我必须在显示结果后销毁Eqntime_标签,以便也输出高程_标签。我该怎么办???

您有几个错误:

def funcname()
GMT = GMT_user.get()
第一行缺少冒号,第二行缺少缩进->

def funcname():
    GMT = GMT_user.get() 
此处的变量名称错误(并且
pack
返回无):

必须是:

Entry(nGui_pgm, textvariable = lat_deg_user).pack()
“我知道我应该销毁第一个标签以输出第二个计算”:不,配置方法是好的。因此,请删除:

Eqntime_label.destroy()

使用
set
而不是
configure
的版本更符合代码中的其他变量定义。
此外,必须缩进与函数对应的所有行。
对于其他问题,已经在其他答案中解释过

from tkinter import *

def funcname():
    #My calculations
    GMT = GMT_user.get()
    lat = lat_deg_user.get()

    E = GMT * 365
    Elevation = E/lat

    etime.set(E)
    elevation.set(Elevation)


root = Tk()

# Getting user input
GMT_user = DoubleVar()
lat_deg_user = DoubleVar()

Label(root, text="Enter time in accordance to GMT in decimal").pack()
nEntry_time = Entry(root, textvariable=GMT_user).pack()

Label(root, text="Enter Latitude in Decimal Degrees").pack()
nEntry_Long = Entry(root, textvariable=lat_deg_user).pack()

nbutton = Button(root, text="Calculate", command=funcname).pack()

# Displaying results
etime = StringVar()
elevation = StringVar()

Label(text="The Equation of Time is").pack()
Eqntime_label = Label(root, textvariable=etime)
Eqntime_label.pack()

Label(text="The Elevation of the sun is").pack()
Elevation_label = Label(root, textvariable=elevation)
Elevation_label.pack()

root.mainloop()

您需要显示更多的代码来重现您的问题。请提供一个@AnandSKumar刚刚编辑了我的代码..请编辑。不清楚哪个代码在
def funcname()
下。记住:最小的,可验证的例子。当前代码将崩溃
from tkinter import *

def funcname():
    #My calculations
    GMT = GMT_user.get()
    lat = lat_deg_user.get()

    E = GMT * 365
    Elevation = E/lat

    etime.set(E)
    elevation.set(Elevation)


root = Tk()

# Getting user input
GMT_user = DoubleVar()
lat_deg_user = DoubleVar()

Label(root, text="Enter time in accordance to GMT in decimal").pack()
nEntry_time = Entry(root, textvariable=GMT_user).pack()

Label(root, text="Enter Latitude in Decimal Degrees").pack()
nEntry_Long = Entry(root, textvariable=lat_deg_user).pack()

nbutton = Button(root, text="Calculate", command=funcname).pack()

# Displaying results
etime = StringVar()
elevation = StringVar()

Label(text="The Equation of Time is").pack()
Eqntime_label = Label(root, textvariable=etime)
Eqntime_label.pack()

Label(text="The Elevation of the sun is").pack()
Elevation_label = Label(root, textvariable=elevation)
Elevation_label.pack()

root.mainloop()