#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    41
    Rep Power
    11

    class calls? please help


    i put in a statusbar.py file this code

    class StatusBar(Frame):

    def __init__(self, master):
    Frame.__init__(self, master)
    self.label = Label(self, bd=1, relief=SUNKEN, anchor=W)
    self.label.pack(fill=X)

    def set(self, format, *args):
    self.label.config(text=format % args)
    self.label.update_idletasks()

    def clear(self):
    self.label.config(text="")
    self.label.update_idletasks()

    and i want from another showbar.py file to call the StatusBar class function. i am writing this

    from Tkinter import *
    root = Tk()

    status = StatusBar(root)
    status.pack(side=BOTTOM, fill=X)

    mainloop()

    but i get an error saying

    Traceback (most recent call last):
    File "C:\Python23\showbar.py", line 6, in ?
    status = StatusBar(root)
    NameError: name 'StatusBar' is not defined

    help! please
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Just add import statusbar to the top of you're file and you should be away. Im assuming that statusbar.py is in the same directory as you're program or is otherwise visable to Python - on Pythons search path (PYTHONPATH) i.e. site-packages

    you will then need to preceed the call to StatusBar() with the name of the module you are using. So you end up with:

    Code:
    import statusbar
    ...
    more code
    ...
    status = statusbar.StatusBar(root)
    status.pack(side=BOTTOM, fill=X)
    ...
    more code
    ...
    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo