[英]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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.