So I am trying to import my own custom style methods into my main app to then use as a custom style in ttk.Label(), by calling the class method, but I'm having trouble finding a way to call it. Below is the example code of the main app.
import tkinter as tk
from tkinter import ttk
from custom_styles import customStyle
class MainApp:
def __init__(self, master):
self.master = master
**initialization code****
#----style methods-----#
self.styled = customStyle(self.master)
#title label
self.title_label = ttk.Label(self.master, text="test", style=self.styled.test())
self.title_label.pack()
And below is the class I am calling the methods above from, which is different file.
from tkinter import ttk
import tkinter as tk
class customStyle:
def __init__(self, master) -> None:
self.master = master
def test(self):
style = ttk.Style()
style.configure("test.TLabel",
foreground="white",
background="black",
padding=[10, 10, 10, 10])
I've tried to call just the name of the style method like this
self.title_label = ttk.Label(self.master, text="test", style='test.TLabel')
I've also tried to call the method by calling the class then method like this
self.title_label = ttk.Label(self.master, text="test", style=self.styled.test())
I knew this wouldn't work, but I still tried it
self.title_label = ttk.Label(self.master, text="test", style=self.styled.test('test.TLabel'))
I also tried not making an object out of the methods, so I took away the class and just made a list of functions, but that didn't work either. Of course, I looked on the internet and searched stack for questions, but to no avail. Maybe this structure I am trying to maintain is not efficient?
I'm honestly just looking to understand a way to call the methods w/o putting them in the same file, but I just don't know how to.