Fredrik Lundh | 5 Sep 2004 16:13
Gravatar

ANN: WCK for Tkinter 1.1 alpha 1 (september 5, 2004)

The Widget Construction Kit (WCK) is an extension API that allows
you to implement custom widgets in pure Python.  The WCK can be
(and is being) used for everything from light-weight display widgets
to full-blown editor frameworks.

The Tkinter3000 implementation of the WCK supports all recent
versions of Python and Tk/Tkinter.

The 1.1 alpha release adds the ability to change widget controllers,
and also adds an experimental native graphics driver for Windows.

Introduction:
    http://www.effbot.org/zone/wck-1.htm

Downloads:
    http://www.effbot.org/downloads#tkinter3000

Documentation:
    http://www.effbot.org/zone/wck.htm
    http://www.effbot.org/zone/wck-api.htm

enjoy /F 
Gurpreet Sachdeva | 8 Sep 2004 15:07
Favicon

Problem with the special characters while parsing XML SAX

 
 
I am parsing an XML file using xml.sax and xml.sax.handler
But the program does not run succesfully as there are some special characters in the XML file. Where can be the problem? How can I find the special characters and escape them. Can I convert them into Unicode? Can anybody point to a good document? Thanks alot...

[CODE SNIPPET]
if __name__ =='__main__':
     try:
          doccorpus = raw_input('enter file: ')
          parser = xml.sax.make_parser()
          handler = docHandler()
          parser.setContentHandler(handler)
          parser.parse(doccorpus)
          print 'file parsed successfully'
     except:
          print position
          print 'file parsing unsuccessful'
[/CODE SNIPPET]



_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
Fredrik Lundh | 8 Sep 2004 20:27
Gravatar

Re: Problem with the special characters while parsingXML SAX

Gurpreet Sachdeva wrote:

> I am parsing an XML file using xml.sax and xml.sax.handler
> But the program does not run succesfully as there are some special characters in the XML file.
> Where can be the problem? How can I find the special characters and escape them. Can I
> convert them into Unicode? Can anybody point to a good document?

this is a Tkinter mailing list, not an XML mailing list.  post your question
to comp.lang.python, or the Python xml-sig mailing list.

</F> 
Dahlke, Doug | 9 Sep 2004 01:04

Can't find info on linking TKinter to Python on UNIX

I haven't posted to this news group and I usually look all over for
other options rather than bother other people.  I have been looking
everywhere for any information on how to install the link between Python
1.6 (unfortunately) and Tcl on SCO Openserver Unix (5.05 version).  I
see all the makefile information in the python library, but it seems to
be missing a library reference.  I down loaded the files from SCO's
skunkware section.  Silly of me to think it would actually work.  Also
tried on Unixware as well.  Has anyone had any experience with SCO?  I
thank you in advance for any help, even if there is not help.  I do have
2.2 source, but it has problems compiling on Unixware. Thanks.

Doug Dahlke
Shields Bag and Printing
Yakima, WA
Fredrik Lundh | 9 Sep 2004 11:39
Gravatar

Re: Can't find info on linking TKinter to Python on UNIX

Doug wrote:

> I haven't posted to this news group and I usually look all over for
> other options rather than bother other people.  I have been looking
> everywhere for any information on how to install the link between Python
> 1.6 (unfortunately) and Tcl on SCO Openserver Unix (5.05 version).  I
> see all the makefile information in the python library, but it seems to
> be missing a library reference.  I down loaded the files from SCO's
> skunkware section.  Silly of me to think it would actually work.  Also
> tried on Unixware as well.  Has anyone had any experience with SCO?  I
> thank you in advance for any help, even if there is not help.  I do have
> 2.2 source, but it has problems compiling on Unixware. Thanks.

you need the right Tcl and Tk libraries; I don't recall what version 1.6 used,
but 8.0 or 8.1 should probably work.  you can get 8.0 and newer here:

    http://www.tcl.tk/software/tcltk/choose.html

you can probably figure out the preferred version by looking at the README
and/or the Modules/Setup file.

if you have the libraries, make sure that the Setup file points to the right locations.

however, Python 1.6 is a totally broken release (it's basically an early 2.0 alpha,
released for contractual reasons). if newer versions don't work for you, you're
probably better off with 1.5.2 (which works with Tcl/Tk 8.0).

    http://www.python.org/1.5/

you could also try to build 2.1 or 2.0

    http://www.python.org/2.1.3/
    http://www.python.org/2.0.1/

</F> 
Dahlke, Doug | 9 Sep 2004 16:52

RE: Re: Can't find info on linking TKinter to Pythonon UNIX

I looked again.  I have version 2.2 on Unixware and 1.5.2 on the
openserver.  I also have TK 8.0pw and 8.1.1 installed on the openserver.
Apparently the total source isn't there from SCO's distro for linking in
TK as I don't see any references to making tk in the module libraries.
I'll put the 'real' source for 2.2 on my openserver.  I've tried to link
the 2.2 from source and run into problems.  Also the version of TCL on
sco is their own special version that can do gui or ncurses depending on
if DISPLAY is defined.  Has anyone used that?  I'm sure it's not
compatible probably.  Anyway, I'll uninstall all of that and try using
your source to set up one that works. If I still have trouble, you may
hear from me again.  I hope that's alright.  Thanks for the quick reply.

Doug

-----Original Message-----

you need the right Tcl and Tk libraries; I don't recall what version 1.6
used,
but 8.0 or 8.1 should probably work.  you can get 8.0 and newer here:

    http://www.tcl.tk/software/tcltk/choose.html

you can probably figure out the preferred version by looking at the
README
and/or the Modules/Setup file.

if you have the libraries, make sure that the Setup file points to the
right locations.

however, Python 1.6 is a totally broken release (it's basically an early
2.0 alpha,
released for contractual reasons). if newer versions don't work for you,
you're
probably better off with 1.5.2 (which works with Tcl/Tk 8.0).

    http://www.python.org/1.5/

you could also try to build 2.1 or 2.0

    http://www.python.org/2.1.3/
    http://www.python.org/2.0.1/
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
stewart | 10 Sep 2004 17:56

Re: [TkinterHow to change font sizes in a Tkinter app?

I'd like to be able to change font size in my Tkinter app.   I've attached a
sample app below that allow for this. Problem is, the method is run when the
menus are drawn, but doesn't run afterward.  How do I stop the font sizes from
changing when the app is started up?  One way might be a lambda function, but is
there any other cleaner solution? Thanks!

cheers
Stewart

---
title = 'FontSize demonstration'

# Import Pmw from this directory tree.
import sys
sys.path[:0] = ['../../..']

import Tkinter
import Pmw

class Demo:
    def __init__(self, parent):

        #Define a base font for use in all widgets
        #this can be changed later in the Options menu
        self.font=('Helvetica', 10, 'normal')

	# Create and pack the MenuBar.
	menuBar = Pmw.MenuBar(parent,
		hull_relief = 'raised',
		hull_borderwidth = 1)
	menuBar.pack(fill = 'x')
	self.menuBar = menuBar

	# Add some buttons to the MenuBar.
	menuBar.addmenu('File', 'Close this window or exit', font=self.font)
	menuBar.addmenuitem('File', 'command', 'Close this window',
		command = PrintOne('Action: close'),
        font=self.font,
		label = 'Close')
	menuBar.addmenuitem('File', 'separator')
	menuBar.addmenuitem('File', 'command', 'Exit the application',
		command = lambda: sys.exit("Bye"),
        font=self.font,
		label = 'Exit')

#		command = PrintOne('Action: exit'),

	menuBar.addmenu('Options', 'Set user preferences', font=self.font)
	menuBar.addcascademenu('Options', 'Size',
		'Set some other preferences', traverseSpec = 'z', tearoff = 1, font=self.font)
	for size in ('tiny', 'small', 'average', 'big', 'huge', 'monstrous'):
	    menuBar.addmenuitem('Size', 'command', 'Set size to ' + size,
                    command = self.setFont(size),
                    font=self.font,
                    label = size)

	# Create and pack the main part of the window.
	self.mainPart = Tkinter.Label(parent,
		text = 'This is the\nmain part of\nthe window',
        font=self.font,
		background = 'white',
		foreground = 'black',
		padx = 30,
		pady = 30)
	self.mainPart.pack(fill = 'both', expand = 1)

    def setFont(self, size):
        print 'current font size: ',self.font[1]
        #('tiny', 'small', 'average', 'big', 'huge')
        newFont = {'tiny': ('Helvetica', 6, 'normal'), 
                    'small': ('Helvetica', 8, 'normal'), 
                    'average': ('Helvetica', 10, 'normal'), 
                    'big': ('Helvetica', 12, 'normal'),
                    'huge': ('Helvetica', 14, 'normal'),
                    'monstrous': ('Helvetica', 18, 'normal')}
        self.font = newFont[size]
        print 'new font size: ', size
        root.update()

class PrintOne:
    def __init__(self, text):
        self.text = text

    def __call__(self):
        print self.text

######################################################################

# Create demo in root window for testing.
if __name__ == '__main__':
    root = Tkinter.Tk()
    Pmw.initialise(root)
    root.title(title)

    exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
    exitButton.pack(side = 'bottom')
    widget = Demo(root)
    root.mainloop()
stewart | 10 Sep 2004 19:57

Re: How to change font sizes in a Tkinter app?

I found out how to stop my font-changing method to be called when I draw the
menus.  I simply created a lambda function to pass the new font size to
font-changing method.  

I've also confirmed that the method does actually change the default font size
for my application.  

Now my only problem is how to get everything to be redrawn, so that the new font
size becomes visible.  Any help is appreciated.  The latest version of my test
app is below.

thanks
Stewart

---
title = 'FontSize demonstration'

# Import Pmw from this directory tree.
import sys
sys.path[:0] = ['../../..']

import Tkinter
import Pmw

class Demo:
    def __init__(self, parent):

        #Define a base font for use in all widgets
        #this can be changed later in the Options menu
        self.font=('Helvetica', 10, 'normal')

	# Create and pack the MenuBar.
	menuBar = Pmw.MenuBar(parent,
		hull_relief = 'raised',
		hull_borderwidth = 1)
	menuBar.pack(fill = 'x')
	self.menuBar = menuBar

	# Add some buttons to the MenuBar.
	menuBar.addmenu('File', 'Close this window or exit', font=self.font)
	menuBar.addmenuitem('File', 'command', 'Close this window',
		command = PrintOne('Action: close'),
        font=self.font,
		label = 'Close')
	menuBar.addmenuitem('File', 'separator')
	menuBar.addmenuitem('File', 'command', 'Exit the application',
		command = lambda: sys.exit("Bye"),
        font=self.font,
		label = 'Exit')

#		command = PrintOne('Action: exit'),

	menuBar.addmenu('Options', 'Set user preferences', font=self.font)
	menuBar.addcascademenu('Options', 'Size',
		'Set some other preferences', traverseSpec = 'z', tearoff = 1, font=self.font)
	for size in ('tiny', 'small', 'average', 'big', 'huge', 'monstrous'):
	    menuBar.addmenuitem('Size', 'command', 'Set size to ' + size,
                    command = lambda ss=size: self.setFont(ss),
                    font=self.font,
                    label = size)

	# Create and pack the main part of the window.
	self.mainPart = Tkinter.Label(parent,
		text = 'This is the\nmain part of\nthe window',
        font=self.font,
		background = 'white',
		foreground = 'black',
		padx = 30,
		pady = 30)
	self.mainPart.pack(fill = 'both', expand = 1)

    def setFont(self, size):
        print 'current font size: ',self.font[1]
        #('tiny', 'small', 'average', 'big', 'huge')
        newFont = {'tiny': ('Helvetica', 6, 'normal'), 
                    'small': ('Helvetica', 8, 'normal'), 
                    'average': ('Helvetica', 10, 'normal'), 
                    'big': ('Helvetica', 12, 'normal'),
                    'huge': ('Helvetica', 14, 'normal'),
                    'monstrous': ('Helvetica', 18, 'normal')}
        self.font = newFont[size]
        print 'new font size: ', size, self.font
        self.menuBar.update

class PrintOne:
    def __init__(self, text):
        self.text = text

    def __call__(self):
        print self.text

######################################################################

# Create demo in root window for testing.
if __name__ == '__main__':
    root = Tkinter.Tk()
    Pmw.initialise(root)
    root.title(title)

    exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
    exitButton.pack(side = 'bottom')
    widget = Demo(root)
    root.mainloop()
stewart | 11 Sep 2004 00:07

Re: How to change font sizes in a Tkinter app?

hi again:

Giving further thought to the problem of how to have a live change of font sizes
in a Tkinter app, I tried using a Tkinter.StringVar.  The modified test app is
below.  It works, as least insofar as it correctly gets and sets the var, but I
still see any visible changes. Somehow I need to force a re-draw of the entire
app. any ideas?

I guess if this is not possible, I could simply write out the new font size to a
.ini file, ask the user to restart the app, and read that .ini file when I start
up. Seems kinda kludgy, though.

S

----

title = 'FontSize demonstration'

# Import Pmw from this directory tree.
import sys
sys.path[:0] = ['../../..']

import Tkinter
import tkFont
import Pmw

class Demo:
    def __init__(self, parent):

        myVar = Tkinter.StringVar()
        self.myVar = myVar
        myVar.set("('Helvetica', 10, 'normal')")
        s = myVar.get()
        print 'myVar is ', str(s)
        self.myVar = myVar
        #CallbackName = self.myVar.trace_variable('w', callbackFunc)

        #Define a base font for use in all widgets
        #this can be changed later in the Options menu

        #self.font=('Helvetica', 10, 'normal')
        self.font = eval(s)

        fontTiny = tkFont.Font(family="Helvetica", size=6)
        fontSmall = tkFont.Font(family="Helvetica", size=8)
        fontAverage = tkFont.Font(family="Helvetica", size=10)
        fontBig = tkFont.Font(family="Helvetica", size=12)
        fontHuge = tkFont.Font(family="Helvetica", size=14)
        fontMonstrous = tkFont.Font(family="Helvetica", size=18)
        self.fontTiny = fontTiny
        self.fontSmall = fontSmall
        self.fontAverage = fontAverage
        self.fontBig = fontBig
        self.fontHuge = fontHuge
        self.fontMonstrous = fontMonstrous

       
	# Create and pack the MenuBar.
	menuBar = Pmw.MenuBar(parent,
		hull_relief = 'raised',
		hull_borderwidth = 1)
	menuBar.pack(fill = 'x')
	self.menuBar = menuBar

	# Add some buttons to the MenuBar.
	menuBar.addmenu('File', 'Close this window or exit', font=self.font)
	menuBar.addmenuitem('File', 'command', 'Close this window',
		command = PrintOne('Action: close'),
        font=self.font,
		label = 'Close')
	menuBar.addmenuitem('File', 'separator')
	menuBar.addmenuitem('File', 'command', 'Exit the application',
		command = lambda: sys.exit("Bye"),
        font=self.font,
		label = 'Exit')

#		command = PrintOne('Action: exit'),

	menuBar.addmenu('Options', 'Set user preferences', font=self.font)
	menuBar.addcascademenu('Options', 'Size',
		'Set some other preferences', traverseSpec = 'z', tearoff = 1, font=self.font)
	for size in ('tiny', 'small', 'average', 'big', 'huge', 'monstrous'):
	    menuBar.addmenuitem('Size', 'command', 'Set size to ' + size,
                    command = lambda ss=size: self.setFont(ss),
                    font=self.font,
                    label = size)

	menuBar.addmenuitem('Options', 'command', 'Change font size',
		command = lambda: self.chgFont(),
        font=self.font,
		label = 'Change size')

	# Create and pack the main part of the window.
	self.mainPart = Tkinter.Label(parent,
		text = 'This is the\nmain part of\nthe window',
        font=eval(self.myVar.get()),
		background = 'white',
		foreground = 'black',
		padx = 30,
		pady = 30)
	self.mainPart.pack(fill = 'both', expand = 1)

    def setFont(self, size):
        print 'current font: ',self.font
        #('tiny', 'small', 'average', 'big', 'huge')

        newFont = {'tiny': ('Helvetica', 6, 'normal'), 
                    'small': ('Helvetica', 8, 'normal'), 
                    'average': ('Helvetica', 10, 'normal'), 
                    'big': ('Helvetica', 12, 'normal'),
                    'huge': ('Helvetica', 14, 'normal'),
                    'monstrous': ('Helvetica', 18, 'normal')}
        '''
        newFont = {'tiny': self.fontTiny,
                    'small': self.fontSmall,
                    'average': self.fontAverage,
                    'big': self.fontBig,
                    'huge': self.fontHuge,
                    'monstrous': self.fontMonstrous}
        '''
        self.font = newFont[size]
        print 'new font size: ', size, ' ', str(self.font)
        self.menuBar.update_idletasks

        self.myVar.set("('Helvetica', 6, 'normal')")
        s = self.myVar.get()
        print 'myVar is now ', s
        #self.mainPart.configure(font=self.font)
        root.update_idletasks()

    def chgFont(self):
        print 'current font: ',self.font
        #('tiny', 'small', 'average', 'big', 'huge')

        self.myVar.set("('Helvetica', 6, 'normal')")
        s = self.myVar.get()
        print 'myVar is now ', s
        root.update_idletasks()

class PrintOne:
    def __init__(self, text):
        self.text = text

    def __call__(self):
        print self.text

######################################################################

# Create demo in root window for testing.
if __name__ == '__main__':
    root = Tkinter.Tk()
    Pmw.initialise(root)
    root.title(title)

    exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
    exitButton.pack(side = 'bottom')
    widget = Demo(root)
    root.mainloop()
Michael Lange | 11 Sep 2004 02:37
Picon
Favicon

Re: Re: How to change font sizes in a Tkinter app?

On Fri, 10 Sep 2004 16:07:30 -0600
stewart <at> midtoad.homelinux.org wrote:

> hi again:
> 
> Giving further thought to the problem of how to have a live change of font sizes
> in a Tkinter app, I tried using a Tkinter.StringVar.  The modified test app is
> below.  It works, as least insofar as it correctly gets and sets the var, but I
> still see any visible changes. Somehow I need to force a re-draw of the entire
> app. any ideas?
> 

Hi Stewart,

maybe the easiest would be to put all the widgets that use the font in a list and then do something like:

for widget in widgetlist:
    widget.configure(font=newFont)

when the user changes the font.

> I guess if this is not possible, I could simply write out the new font size to a
> .ini file, ask the user to restart the app, and read that .ini file when I start
> up. Seems kinda kludgy, though.
> 
> S
> 
>
I think the usual way to do this is to use an option database which allows to override default tk options
like fonts and colors (in case you want to change the default font for the whole app). Entries in an option database
look like this:

*font : Helvetica -12
*Entry*background : white
*Listbox*background : white
*Listbox*exportSelection : 0
*selectBackground : #a0a
*selectForeground : white
*Scrollbar*Width : 12

If you store this in a file "optionDB" in the application's directory you can access the options with option_readfile():

root = Tk()
root.option_readfile(sys.path[0]+"/optionDB")

The options apply to all children of root that are created after option_readfile() is called, however
I don't think it's possible to apply changes to the option database to widgets that already exist this way.

I hope this helps

Michael

Gmane