2
I am trying to create separate fonts for my project in a particular.py file, after creating them I care for the.py project, I do it this way as follows:
py.
"""
Criando as fontes.
"""
def fontes(self):
self.font1=("Arial", "60")
py project.
from Tkinter import *
from fonte import *
class base:
def __init__(self, janela):
caixa=Frame(janela)
caixa.pack()
a=Label(caixa, text="teste para o funcionamento das fontes", font=self.font1)
a.pack()
root=Tk()
base(root)
root.mainloop()
But when I try to use the source:
a = Label(caixa, text="teste para o funcionamento das fontes", font=font1)
She’s making a mistake and says she’s not global:
Nameerror: global name 'font1' is not defined
Could someone tell me how I can make use of sources without being within the project itself?
Hi - so the code you put here should be ok (I haven’t tested, but it doesn’t look good -- come to think of it, pq. Does your "fonts" function have the "self" parameter?? It doesn’t look so good anymore... :-/) - but O.P. is having doubts about how Python works, confusing functions with classes, for example, using recognized bad practices (
from X import *
) - what do you think about giving a touch on these things to improve your response. I.e.: clarifying what is wrong, not only posting some lines that work?– jsbueno