我想我在这个 tkinter 小部件上犯了一个错误
I think I made a mistake with this tkinter widget
所以到目前为止我想制作一个简单的按钮,但它给我一个错误屏幕,我做错了什么?这是我的代码:
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
所以到目前为止我想制作一个简单的按钮,但它给我一个错误屏幕,我做错了什么?这是我的代码:
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