首页 > 解决方案 > 为什么python在以下代码中显示“TclError:无法调用“place”命令:应用程序已被破坏”

问题描述

import tkinter as tk

def close_window():
    print ("")
    window.destroy()

window = tk.Tk()
window.geometry("750x350")

username = tk.Label(window, text = "Enter Username")

password = tk.Label(window, text = "Enter Password")

input1 = tk.Entry(window)

input2 = tk.Entry(window, show = "*")

confirm = tk.Button(text="Confirm", command = close_window()) 

input1.place(x=400, y=35)

input2.place(x=400, y=65)

username.place(x=150, y=35)

password.place(x=150, y=65)

confirm.place(x=400, y=100)

confirm.pack()

window.mainloop()

我正在尝试创建一个在您单击确认后自行关闭的论坛。另外,我使用 spyder(以防万一),我刚刚开始了 tkinter 的概念。我试图在谷歌上找到答案,但没有那么成功。

标签: pythontkinter

解决方案


您在这一行中调用“close_window()”:“confirm = tk.Button(text="Confirm", command = close_window())”


推荐阅读