Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37710 > unrolled thread
| Started by | Angel <angel.gutierrez.rodriguez@gmail.com> |
|---|---|
| First post | 2013-01-25 20:41 -0800 |
| Last post | 2013-01-30 02:08 -0800 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.python
Fonts & Tinker Angel <angel.gutierrez.rodriguez@gmail.com> - 2013-01-25 20:41 -0800
Re: Fonts & Tinker Angel <angel.gutierrez.rodriguez@gmail.com> - 2013-01-25 20:42 -0800
Re: Fonts & Tinker Paul <aquagnu@gmail.com> - 2013-01-25 21:18 -0800
Re: Fonts & Tinker Rick Johnson <rantingrickjohnson@gmail.com> - 2013-01-27 07:34 -0800
Re: [SPAM] Fonts & Tinker Łukasz Posadowski <mail@lukaszposadowski.pl> - 2013-01-28 12:28 +0100
Re: Fonts & Tinker Angel <angel.gutierrez.rodriguez@gmail.com> - 2013-01-30 02:08 -0800
| From | Angel <angel.gutierrez.rodriguez@gmail.com> |
|---|---|
| Date | 2013-01-25 20:41 -0800 |
| Subject | Fonts & Tinker |
| Message-ID | <5356f7a4-252a-46ac-8225-c8dec1fe9523@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Angel <angel.gutierrez.rodriguez@gmail.com> |
|---|---|
| Date | 2013-01-25 20:42 -0800 |
| Message-ID | <5cf7db22-8108-4255-996b-87bf44066f2a@googlegroups.com> |
| In reply to | #37710 |
Dammm it should be Tkinter for subject..:D
[toc] | [prev] | [next] | [standalone]
| From | Paul <aquagnu@gmail.com> |
|---|---|
| Date | 2013-01-25 21:18 -0800 |
| Message-ID | <d567d311-de62-4211-85dc-63767203a018@googlegroups.com> |
| In reply to | #37710 |
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
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2013-01-27 07:34 -0800 |
| Message-ID | <ac779273-bce7-4b6a-aa05-a5aec4535fcb@googlegroups.com> |
| In reply to | #37710 |
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/pubs/tkinter/web/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.
[toc] | [prev] | [next] | [standalone]
| From | Łukasz Posadowski <mail@lukaszposadowski.pl> |
|---|---|
| Date | 2013-01-28 12:28 +0100 |
| Subject | Re: [SPAM] Fonts & Tinker |
| Message-ID | <mailman.1128.1359372662.2939.python-list@python.org> |
| In reply to | #37710 |
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
[toc] | [prev] | [next] | [standalone]
| From | Angel <angel.gutierrez.rodriguez@gmail.com> |
|---|---|
| Date | 2013-01-30 02:08 -0800 |
| Message-ID | <1d69c340-0824-48d6-b3ec-7e27b7175bb3@googlegroups.com> |
| In reply to | #37710 |
THis one workd fine:
.....option_add('*Font', "Heveltica 14")
Thanks!
Á.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web