thanks for reading:
OBJECTIVE:
I am practicing using OOP, and wanted to create a class with class variables for a label widget I'm creating with tkinter. This way I can create many labels and don't need to specify the same font, font size, colors, etc, for each one.
PROBLEM:
I am unable to figure out how I can call a class instance when it needs to also reference the tkinter method. (Alternatively, should I even be trying to include the tkinter reference when creating a class?)
Here's an example of what I have:
import tkinter as tk
class ui_Labels:
"This class sets the baseline characteristics for the widgets, including font, font size, and colors"
#If I understand correctly, below are called class attributes#
tkLabel = tk.Label
rootRef = uiRoot
varFont = "Calibri"
fontSize = 14
varFG = "f2f2f2"
varBG = "#3b3b3b"
#Constructor
def __init__(self, name, varText):
self.name = name
self.varText = varText
# CLASS OBJECTS
sectionHeader = ui_Labels("Section Header","Magic XML Iterator")
# Attempt to call the instance (not sure if that's the correct phrasing
tk.Label(sectionHeader)
When to call the sectionHeader object as a tk.Label, I get the AttributeError message: "ui_Labels' object has no attribute 'tk'.
It looks like the message is saying that I need to reference the tk method in the class, but I wasn't sure how best to do so.
TL;DR Question:
Does anyone have a suggestion on the best way write a class or its associated object(s) for the purpose of making tkinter Widget templates?
Thank you!
Best,
Chris