我想我在这个tkinter小部件上犯了一个错误



所以到目前为止,我想制作一个简单的按钮,但它给了我一个错误屏幕,我做错了什么?这是我的代码:

import tkinter as tk
import math
import time
tk = tk.Tk()
tk.geometry()
tk.attributes("-fullscreen", True)
exit_button = tk.Button(tk, text = "Exit", height = 2, width = 2, command = tk.destroy)
exit_button.place(x=1506, y=0)


tk.mainloop()

您正在用其他东西跟踪tk

import tkinter as tk
root = tk.Tk()
root.geometry()
root.attributes("-fullscreen", True)
exit_button = tk.Button(root, text="Exit", height=2, width=2, command=root.destroy)
exit_button.place(x=1506, y=0)

tk.mainloop()

您不能使用tk = tk.Tk(),因为您也将tkinter称为tk。所以要么:

更改您的进口(不推荐(:

import tkinter as _tk
tk = _tk.Tk() # And so on..

或更改您的变量名称(推荐(:

root = tk.Tk() # And change tk.geometry to root.geometry() and so on

相关内容

最新更新