Python Forum

Full Version: Python code issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys,
I am new python learner. Today I meet one attribute error. I am not sure why it happens.Please advise.Please refer the code and screenshot below.
Thanks in advance.

[Image: c893fa?filename=1586975832641_python+que...height=801]

#++++++++++++++++++++++++++++++++++++++++++++++++++++

from tkinter import *
class BuckysButtons:
    def __init__(self, master):
        frame = Frame(master)
        frame.pack()
        self.printButton = Button(frame, text="Print Message", command=self.printMessage)
        self.printButton.pack(side=LEFT)

        self.quitButton = Button(frame, text="Print Message", command=self.quit)
        self.quitButton.pack(side=LEFT)

    def printMessage(self):
        print("wow, this actually worked")

root = Tk()
b = BuckysButtons(root)
root.mainloop() # windows looping does not disappear
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Error message

Error:
Traceback (most recent call last): File "H:/Knowledge/Python/Python Practice/Python/TKinter.py", line 84, in <module> b = BuckysButtons(root) File "H:/Knowledge/Python/Python Practice/Python/TKinter.py", line 77, in __init__ self.quitButton = Button(frame, text="Print Message", command=self.quit) AttributeError: 'BuckysButtons' object has no attribute 'quit'
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
when the print button is clicked you have a method printMessage that is able to be called.
when the quit button is clicked you don't have a method quit that is able to be called.
(Apr-15-2020, 06:50 PM)Yoriz Wrote: [ -> ]when the print button is clicked you have a method printMessage that is able to be called.
when the quit button is clicked you don't have a method quit that is able to be called.

Thanks Admin, I got it and test is ok. Many thanks.