Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Fonts & Tinker

Reply
Thread Tools

Fonts & Tinker

 
 
Angel
Guest
Posts: n/a
 
      01-26-2013
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=1
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.

 
Reply With Quote
 
 
 
 
Angel
Guest
Posts: n/a
 
      01-26-2013
Dammm it should be Tkinter for subject..
 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      01-26-2013
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
 
Reply With Quote
 
Rick Johnson
Guest
Posts: n/a
 
      01-27-2013
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=1
>
> 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.
 
Reply With Quote
 
Łukasz Posadowski
Guest
Posts: n/a
 
      01-28-2013

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



 
Reply With Quote
 
Angel
Guest
Posts: n/a
 
      01-30-2013
THis one workd fine:

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

Thanks!

.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fonts suddenly unreadable in IE 6.0 - All other system fonts appear normal Emily Computer Support 3 06-09-2005 04:52 AM
asp fonts problems (chinese fonts become ??????) sam ASP General 0 06-06-2004 06:15 AM
Tinker, Tailor, Soldier, Spy Length Question Nobody DVD Video 3 05-18-2004 05:45 PM
Absurd fonts... :( ::spidernik:: Firefox 1 11-24-2003 06:29 PM
Re: firebird fonts horrible and thin Gunther Firefox 1 07-19-2003 01:10 PM



Advertisments