|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > class calls? please help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|