I am a very new coder / python user and I don't really understand much. I am trying to understand classes and right now and my program is divided into two of them. I am trying to program a sort of "notepad" and I would like to have a "font changer menu". My main window and my "font changer menu" are in separate classes.
My problem is that I am trying to edit the Text Area(change its font), from the "font changer menu", but they are in separate classes. You can see I have tried putting the font_chooser
command inside the "font changer menu" class, but I am obviously told that Our_font
is not defined yet, because it is in the other class and therefore cannot edit it with the command. Suggestions on how I should approach something like this?
class fontchangerframe:
def __init__(self):
def font_chooser(e):
self.our_font.config(family=fontbox.get(fontbox.curselection()))
self.fontchanger = Toplevel()
self.fontchanger_frame = Frame(self.fontchanger)
self.fontchanger_frame.pack()
self.fontbox = Listbox(self.fontchanger_frame, selectmode=SINGLE, width=80)
self.fontbox.pack()
#Add font families to Listbox
for f in font.families():
self.fontbox.insert('end', f)
# Bind the list box
self.fontbox.bind("<ButtonRelease-1>", font_chooser)
class frontpageframe:
def __init__(self, location):
self.frame = Frame(location, bg="IndianRed3", width=600, height=600)
self.frame.pack()
#Freeze frame in place
self.frame.grid_propagate(False)
# Text area
self.our_font = font.Font(family="Helvetica", size="20")
self.textEditor = Text(self.frame, font=self.our_font)
self.textEditor.grid(row=1, column=1)
# Toolbar
self.toolbarFrame = Frame(self.frame)
self.toolbarFrame.grid(row=0, column=0, pady=5)
# button to open the fontchanger menu
self.font_skift = Button(self.toolbarFrame, text="Font", command=fontchangerframe)
self.font_skift.grid(row=0, column=1)