On Ubuntu MATE 17.04 Python: 3.5
I'm sublassing a ttk Button:
import tkinter as tk
import tkinter.ttk as ttk
class ImgButton(ttk.Button):
"""
Button for holding an image
"""
IMG_NAME = 'filename{}.jpg'
IMAGES_DIR = os.path.sep + os.path.sep.join(['home', 'user', 'MyProjects', 'myProject', 'resources', 'images'])
UNKNOWN_IMG = os.path.sep.join([IMAGES_DIR, IMG_NAME.format(0)])
IMAGES = [os.path.sep.join([IMAGES_DIR, IMG_NAME.format(i)]) for i in [1,2,3,4,5,6]]
# ... more code... You can add an empty __init__() if you like so
if __name__ == '__main__':
root = tk.Tk()
ImgButton(root).pack()
When using the button it gives me an error:
NameError: name 'IMAGES_DIR' is not defined
How is it possible that UNKNOWN_IMAGE has no problem using the IMAGES_DIR variable and IMAGES raises this error???
I'm shocked with this. Do I need some static initializer? Do I need to refer to he variable in another way? In the former line it worked with nothing. And I tried ImgButton.IMAGES_DIR and it doesn't work.
How should I solve this problem? And the most important thing, what am I doing wrong?