Python Forum
[Tkinter] Python code issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Python code issue
#1
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'
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Reply
#2
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.
Reply
#3
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020