Tkinter-helper-gui and a main class: their communication

Greg Krohn gkrohn at tcq.net
Thu May 2 04:11:20 EDT 2002


Yeah, so assuming you don't need the exception-event-handling, this is how I
would do it.


#turtle.py
from Tkinter import *

class Amphibian_gui:
    def __init__(self):
        pass

class Turtle_gui(Amphibian_gui):
    def __init__(self):
        Amphibian_gui.__init__(self)
        self.knop=Button(root,text='New Turtle')
        self.knop.grid(row=0,column=0)


class Turtle:
    def __init__(self):
        self.gui = Turtle_gui()
        self.gui.knop.config(command=self.buttonwork)

    def buttonwork(self):
        print "main class Turtle sees the The ButtonPush exception"
        # do something useful with this knowledge

if __name__ == '__main__':
    root = Tk()
    turtle = Turtle()
    root.mainloop()





More information about the Python-list mailing list