Python + Tkinter:“属性错误”

问题描述

我也没有太多的 Python 练习,并且在理解错误方面有一个基本问题:AttributeError: 'NoneType' object has no attribute '_root',它只在我定义 dec 变量时出现BEFORE 定义主窗口win

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 中没有理解什么?

感谢大家的大力帮助和最良好的祝愿 拉斯

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)