Error in font python 2x

2

I'm trying to create separate sources for my project in a given .py file, after creating them I import to the project.py, I do this as follows:

font.py

 
"""
Criando as fontes.
"""
def fontes(self):
    self.font1=("Arial", "60")

project.py

 
 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 font:

 
a = Label(caixa, text="teste para o funcionamento das fontes", font=font1)

It is giving error and says that it is not global:

  

NameError: global name 'font1' is not defined

Can anyone tell me how I can use fonts without being inside the project itself?

    
asked by anonymous 15.08.2014 / 15:16

1 answer

1

The error is occurring because the system is searching for the variable 'font1' which in your case has never been declared.

You can do the following:

font.py

import tkfont

def fontes(self):
    arial = Font(family="Arial",size=60,weight="normal") 
    return arial

project.py

...
a=Label(caixa, text="teste para o funcionamento das fontes", font=fontes())
...
    
15.08.2014 / 16:17