Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Fonts & Tinker (http://www.velocityreviews.com/forums/t956952-fonts-and-tinker.html)

Angel 01-26-2013 04:41 AM

Fonts & Tinker
 
I am changing the default font for a Tkinter application:

class FuelControl(Tkinter.Frame):
def __init__(self,master):
self.version='0.02'
self.font=tkFont.Font(family="Helvetica",size=18)
print self.font.actual()
..
..
..

and everything looks ok:

{'family': 'Nimbus Sans L', 'weight': 'normal', 'slant': 'roman', 'overstrike': 0, 'underline': 0, 'size': 18}

and the size of the text are 18 on the screen. Then a button creates a new window through this callback:

def loc_add(self):
addw=Tix.Tk()
addw.title('Add location')
print self.font.actual()
Tkinter.Label(addw,text='Nickname:', font=self.font).grid(row=0,column=0)
Tkinter.Label(addw,text='Fullname:', font=self.font).grid(row=1,column=0)
Tkinter.Label(addw,text='Address:', font=self.font).grid(row=2,column=0)
Tkinter.Label(addw,text='Fuel name:',font=self.font).grid(row=3,column=0)
....

The self.font stays with the right value:

{'family': 'Nimbus Sans L', 'weight': 'normal', 'slant': 'roman', 'overstrike': 0, 'underline': 0, 'size': 18}

but the real displayed fonts in the window are smaller (default size of 12, maybe).

Am I missing something?

Thanks in advance,
A.


Angel 01-26-2013 04:42 AM

Re: Fonts & Tinker
 
Dammm it should be Tkinter for subject..:D

Paul 01-26-2013 05:18 AM

Re: Fonts & Tinker
 
class FontSpec:
"""Wrapper for something like 'Arial 10 bold #red'
"""

tkf = None # Tk Font
spec = "" # specification
tkspec = "" # specification for Tk
family = None
size = 0
color = "black"
weight = "normal"
slant = "roman"
underline = 0
overstrike = 0
linespace = 0
descent = 0
ascent = 0

def __init__(self, spec=None):
"""spec: familty with capital letter, color with # (#red, ##FF00FF),
size - int, other are styles"""
try:
if not spec:
return

spec = spec.split()

family = [s for s in spec if s.istitle()]
if family:
self.family = family[0]
spec.remove(self.family)

color = [s for s in spec if s.startswith('#')]
if color:
self.color = color[0]
spec.remove(self.color)
self.color = self.color[1:]

size = [s for s in spec if s.isdigit()]
if size:
self.size = size[0]
spec.remove(self.size)
self.size = int(self.size)

if "bold" in spec:
self.weight = "bold"

if "italic" in spec:
self.slant = "italic"

if "underline" in spec:
self.underline = 1

if "overstrike" in spec:
self.overstrike = 1

# create tkFont for metrics
self.tkf = tkFont.Font(family=self.family, size=self.size, weight=self.weight,
slant=self.slant, underline=self.underline, overstrike=self.overstrike)

self.ascent = self.tkf.metrics("ascent")

self.descent = self.tkf.metrics("descent")

self.linespace = self.tkf.metrics("linespace")

# tkspec - specific. of font in Tk standard
self.tkspec = []
if self.family:
self.tkspec.append(self.family)
if self.size:
self.tkspec.append(str(self.size))
if self.weight == "bold":
self.tkspec.append("bold")
if self.slant == "italic":
self.tkspec.append("italic")
if self.underline:
self.tkspec.append("underline")
if self.overstrike:
self.tkspec.append("overstrike")
self.tkspec = " ".join(self.tkspec)

except:
raise ValueError("invalid font specification")

def __str__(self):
return self.tkspec

--- only for ideas

Rick Johnson 01-27-2013 03:34 PM

Re: Fonts & Tinker
 
On Friday, January 25, 2013 10:41:36 PM UTC-6, Angel wrote:
> I am changing the default font for a Tkinter application:
>
>
>
> class FuelControl(Tkinter.Frame):
>
> def __init__(self,master):
>
> self.version='0.02'
>
> self.font=tkFont.Font(family="Helvetica",size=18)
>
> print self.font.actual()



You may want to check out these universal Tkinter widget methods:

w.option_add(pattern, value, priority=None)
w.option_clear()
w.option_get(name, classname)
w.option_readfile(fileName, priority=None)

http://infohost.nmt.edu/tcc/help/pub...universal.html

While you are there, poke around the docs a bit because there is tons of good info you are going to need in the future. May want to get familiar with the new ttk widgets and themes.

Łukasz Posadowski 01-28-2013 11:28 AM

Re: [SPAM] Fonts & Tinker
 

Dnia 2013-01-25, pią o godzinie 20:41 -0800, Angel pisze:
> but the real displayed fonts in the window are smaller (default size of 12, maybe).
>
> Am I missing something?
>
> Thanks in advance,
> A.
>


Did you tried this by simple:

---------------------------
root = Tk()
root.option_add('*Font', "Heveltica 14")
---------------------------

We'll see if it's a local tkinter installation problem.



--
Łukasz Posadowski




Angel 01-30-2013 10:08 AM

Re: Fonts & Tinker
 
THis one workd fine:

......option_add('*Font', "Heveltica 14")

Thanks!

.


All times are GMT. The time now is 11:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.