我也没有太多使用 Python 的实践,并且在理解错误时遇到了一个基本问题:AttributeError: 'NoneType' object has no attribute '_root'
,它只出现在我在定义主窗口win之前定义dec变量时:
import tkinter as tk
from tkinter import ttk
from tkinter import *
# This variable must be defined AFTER definition of the Tk() window!
dec = tk.BooleanVar()
# Main window
win = Tk()
# # This variable must be defined AFTER definition of the Tk() window!
# dec = tk.BooleanVar()
decreaseButton = Checkbutton(win, text = "Decrease (optional)", variable = dec)
decreaseButton.grid(row=1, column=1, sticky='W')
# Runs the event loop of Tkinter
win.mainloop()
为什么我必须先定义窗口然后再定义布尔变量?我对 Tkinter 有什么不明白的地方?
感谢大家的大力帮助和最良好的祝愿拉斯