AttributeError:尝试更改按钮属性的字体大小时,“ NoneType”对象没有属性“ config”

时间:2019-03-24 00:57:25

标签: python tkinter

当尝试使用.config()方法更改'studentmainmenuscreen'对象的'button1'属性的字体大小时,出现此错误: Error

我不知道为什么会发生此错误!请帮我吗?!

class standardclass: #creates the class called 'standardclass'
    def __init__(self, labeltext, b1t, b1c, b2t, b2c, tlxc, b1x, b1y, b2x, b2y): #creates the initalization subroutine and passes the parameters in the bracket
        self.canvas = Canvas(root, width=600, height=600, highlightthickness=0,  bg='#A9E2f3') #creates the canvas attribute
        self.canvas.pack()  #packs the canvas inside of the root window
        self.titlelabel = Label(self.canvas, text=labeltext, font=('Arial', 30), bg='#A9E2f3').place(x=tlxc,y=20) #creates the title label attribute
        self.button1 = Button(self.canvas, text=b1t, command=b1c, font=('Arial', 30), relief='flat').place(x=b1x,y=b1y) #creates the bottom left button attribute
        self.button2 = Button(self.canvas, text=b2t, command=b2c, font=('Arial', 30), relief='flat').place(x=b2x,y=b2y) #creates the bottom right button attribute

studentmainmenuscreen = standardclass('Main Menu', 'Maths Tests', temporarysubroutine, 'Logout', temporarysubroutine, 225, 200, 300, 200, 400)
studentmainmenuscreen.button1.config(font=('Arial', 20))
studentmainmenuscreen.button1.update()

1 个答案:

答案 0 :(得分:0)

您要更改以下行中的对象类型:

self.button1 = Button(self.canvas, text=b1t, command=b1c, font=('Arial', 30), relief='flat').place(x=b1x,y=b1y)

对于两个按钮。

您可以先创建按钮,然后调用place()方法:

self.button1 = Button(params)
self.button2 = Button(params)
self.button1.place(params)
self.button2.place(params)

这里是一个不错的article可供参考。