Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.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 _tkinter.TclError:can';t调用;标签";命令:应用程序已被销毁_Python_Tkinter - Fatal编程技术网

Python _tkinter.TclError:can';t调用;标签";命令:应用程序已被销毁

Python _tkinter.TclError:can';t调用;标签";命令:应用程序已被销毁,python,tkinter,Python,Tkinter,嗨,这是我在这个网站上的第一篇帖子。最近我在上编程课,我们正在学习tkinter。我试着运行这个程序,盒子里的东西会显示出来,但是盒子里的文本不会显示出来。此错误显示为“\u tkinter.TclError:无法调用“label”命令:应用程序已被销毁”。问题是什么?如何解决?谢谢你的帮助 from tkinter import * #******************* def greet(): n=name.get() print

嗨,这是我在这个网站上的第一篇帖子。最近我在上编程课,我们正在学习tkinter。我试着运行这个程序,盒子里的东西会显示出来,但是盒子里的文本不会显示出来。此错误显示为“\u tkinter.TclError:无法调用“label”命令:应用程序已被销毁”。问题是什么?如何解决?谢谢你的帮助

    from tkinter import *

    #*******************
    def greet():
        n=name.get()
        print(f"{n},good morning")

    #create a window(screen)
    screen=Tk()
    screen.title("GUI thing")
    screen.geometry("380x300")
    screen.mainloop()
    myfont="Times 14 bold"

    # Create a label and put it on the grid
    Label(screen,text="Enter Name:",font= myfont).grid(row=0,column=0)

    # Create an entry box
    name=StringVar()
    Entry(screen,width=15,font=myfont,textvariable=name).grid(row=0,column=1)

    # Create a button
    Button(screen,text="Clik moi",font=myfont,bg="green",fg="white",command=greet).grid(row=1,colum=0)`enter code here`

您需要将
screen.mainloop()
移动到代码末尾:

from tkinter import *


# *******************
def greet():
    n = name.get()
    print(f"{n},good morning")


# create a window(screen)
screen = Tk()
screen.title("GUI thing")
screen.geometry("380x300")
myfont = "Times 14 bold"

# Create a label and put it on the grid
Label(screen, text="Enter Name:", font=myfont).grid(row=0, column=0)

# Create an entry box
name = StringVar()
Entry(screen, width=15, font=myfont, textvariable=name).grid(row=0, column=1)

# Create a button
Button(screen, text="Clik moi", font=myfont, bg="green", fg="white", command=greet).grid(row=1, column=0)

screen.mainloop()

查看。

您需要将
screen.mainloop()
移动到代码末尾:

from tkinter import *


# *******************
def greet():
    n = name.get()
    print(f"{n},good morning")


# create a window(screen)
screen = Tk()
screen.title("GUI thing")
screen.geometry("380x300")
myfont = "Times 14 bold"

# Create a label and put it on the grid
Label(screen, text="Enter Name:", font=myfont).grid(row=0, column=0)

# Create an entry box
name = StringVar()
Entry(screen, width=15, font=myfont, textvariable=name).grid(row=0, column=1)

# Create a button
Button(screen, text="Clik moi", font=myfont, bg="green", fg="white", command=greet).grid(row=1, column=0)

screen.mainloop()
看一看