from tkinter import *
#窗口的宽度和高度
win_width=450
win_height=450
class Application(Frame):
"""开发画图软件"""
def __init__(self,master=None,bgcolor="#000000"):
super().__init__(master)
self.master=master
self.pack()
self.createwidget()
self.bgcolor=bgcolor
def createwidget(self):
"""创建画布区域"""
drawpad=Canvas(root,width=win_width,height=win_height,bg=self.bgcolor)
drawpad.pack()
老师我执行这串代码为什么会报错?
错误:
Traceback (most recent call last):
File "D:\python_exec\py02\GUI图形编程\画图软件.py", line 28, in <module>
app=Application(master=root)
File "D:\python_exec\py02\GUI图形编程\画图软件.py", line 13, in __init__
self.createwidget()
File "D:\python_exec\py02\GUI图形编程\画图软件.py", line 20, in createwidget
drawpad=Canvas(root,width=win_width,height=win_height,bg=self.bgcolor)
AttributeError: 'Application' object has no attribute 'bgcolor'