In the code below I get the error below.
I'm trying to create a class for several widgets and make the "interact" within a main Frame. Can't figure it out (lack of programming experience) and couldn't find an eye opening example.

I understand that the toolbar has no way to access the txt in the editor, how do I make it so?

TIA,

Ingo

ERROR:

Exception in Tkinter callback
Traceback (most recent call last):
  File "\Python35-32\lib\tkinter\__init__.py", line 1549, in __call__
    return self.func(*args)
  File "twoclass.py", line 10, in <lambda>
    command=lambda: self.txt.insert(END, 'Button pressed.\n')
AttributeError: 'Ttoolbar' object has no attribute 'txt'


CODE:

from tkinter import *

class Ttoolbar(Frame):

    def __init__(self, parent=None):
        Frame.__init__(self, parent)
        self.btn = Button(
            self,
            text='Button',
            command=lambda: self.txt.insert(END, 'Button pressed.\n')
        )
        self.btn.pack(side=LEFT)
        self.pack(side=LEFT)


class Eedit(Text):

    def __init__(self, parent=None):
        txt = Text.__init__(self, parent)
        self.pack(fill='both', expand=Y)


class Aapp(Frame):

    def __init__(self, parent=None):
        Frame.__init__(self, parent)
        self.pack()
        self.makeWidgets()


    def makeWidgets(self):
        tb = Ttoolbar().pack(side=TOP, fill=X)
        ed = Eedit().pack()


if __name__ == '__main__':
    Aapp().mainloop()

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to