-1

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

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()
4

2 回答 2

3

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()
于 2021-03-29T17:05:14.673 回答
2

您不能使用tk = tk.Tk(),因为您还指的是tkinteras tk。所以要么:

更改您的导入(不推荐):

import tkinter as _tk

tk = _tk.Tk() # And so on..

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

root = tk.Tk() # And change tk.geometry to root.geometry() and so on
于 2021-03-29T17:05:50.177 回答