From fredrik at pythonware.com Sun Sep 5 16:13:54 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun Sep 5 16:20:34 2004 Subject: [Tkinter-discuss] ANN: WCK for Tkinter 1.1 alpha 1 (september 5, 2004) Message-ID: 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 From redhackgp at rediffmail.com Wed Sep 8 15:07:47 2004 From: redhackgp at rediffmail.com (Gurpreet Sachdeva) Date: Wed Sep 8 15:08:02 2004 Subject: [Tkinter-discuss] Problem with the special characters while parsing XML SAX Message-ID: <20040908130747.12669.qmail@webmail46.rediffmail.com> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20040908/580161ca/attachment.html -------------- next part -------------- ? 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] From fredrik at pythonware.com Wed Sep 8 20:27:03 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed Sep 8 20:25:15 2004 Subject: [Tkinter-discuss] Re: Problem with the special characters while parsingXML SAX References: <20040908130747.12669.qmail@webmail46.rediffmail.com> Message-ID: 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. From DFDahlke at shieldsbag.com Thu Sep 9 01:04:39 2004 From: DFDahlke at shieldsbag.com (Dahlke, Doug) Date: Thu Sep 9 01:04:44 2004 Subject: [Tkinter-discuss] Can't find info on linking TKinter to Python on UNIX Message-ID: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> 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 From fredrik at pythonware.com Thu Sep 9 11:39:14 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu Sep 9 11:39:18 2004 Subject: [Tkinter-discuss] Re: Can't find info on linking TKinter to Python on UNIX References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> Message-ID: 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/ From DFDahlke at shieldsbag.com Thu Sep 9 16:52:37 2004 From: DFDahlke at shieldsbag.com (Dahlke, Doug) Date: Thu Sep 9 16:52:42 2004 Subject: [Tkinter-discuss] Re: Can't find info on linking TKinter to Pythonon UNIX Message-ID: <5F063358AA124D43AE65BE83F89A01622FCD0D@sbpnt6.shields.com> 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@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss From stewart at midtoad.homelinux.org Fri Sep 10 17:56:25 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Fri Sep 10 17:59:59 2004 Subject: [Tkinter-discuss] Re: [TkinterHow to change font sizes in a Tkinter app? In-Reply-To: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> Message-ID: <1094831785.4141cea9e2c77@midtoad.homelinux.org> 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() From stewart at midtoad.homelinux.org Fri Sep 10 19:57:04 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Fri Sep 10 19:57:35 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: <1094831785.4141cea9e2c77@midtoad.homelinux.org> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> Message-ID: <1094839024.4141eaf0be284@midtoad.homelinux.org> 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() From stewart at midtoad.homelinux.org Sat Sep 11 00:07:30 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Sat Sep 11 00:09:45 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: <1094839024.4141eaf0be284@midtoad.homelinux.org> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> Message-ID: <1094854050.414225a2e7b5a@midtoad.homelinux.org> 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() From klappnase at freenet.de Sat Sep 11 02:37:05 2004 From: klappnase at freenet.de (Michael Lange) Date: Sat Sep 11 02:37:22 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: <1094854050.414225a2e7b5a@midtoad.homelinux.org> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> Message-ID: <20040911023705.001a4122.klappnase@freenet.de> On Fri, 10 Sep 2004 16:07:30 -0600 stewart@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 From stewart at midtoad.homelinux.org Sat Sep 11 05:53:33 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Sat Sep 11 05:59:04 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: <20040911023705.001a4122.klappnase@freenet.de> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> Message-ID: <1094874813.414276bdbbbbe@midtoad.homelinux.org> Quoting Michael Lange : > 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 want to change all my menu entries to use the new font. But,I don't see how to get the right name for those items to use in the list since each menu entry doesn't have a discrete object name, like say a button would (btn=Tkinter.Button, so you could have widgetlist=[btn,lbl,btn2]. I read something about using component() to achieve this, but the exact implementation escapes me - the example I saw related to notebook tabs rather than menu entries. > 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: thanks for this useful detail. I'll give it a try on Monday. I did try a similar idea, putting the current font name into another module which I called basefont.py. I built a test app and was able to change the font this way (the user has to quit and restart the app, but that's okay). The strange thing is, when I copy the methods into my real app, it doesn't work due to a scoping problem in the lambda function I use. I'll post the details on that on Monday. thanks Stewart From mfranklin1 at gatwick.westerngeco.slb.com Sat Sep 11 16:47:46 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Sat Sep 11 16:48:17 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: <1094874813.414276bdbbbbe@midtoad.homelinux.org> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> Message-ID: On Fri, 10 Sep 2004 21:53:33 -0600, wrote: > Quoting Michael Lange : > >> 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 want to change all my menu entries to use the new font. But,I don't > see how > to get the right name for those items to use in the list since each menu > entry > doesn't have a discrete object name, like say a button would > (btn=Tkinter.Button, so you could have widgetlist=[btn,lbl,btn2]. I read > something about using component() to achieve this, but the exact > implementation > escapes me - the example I saw related to notebook tabs rather than menu > entries. > >> 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: > > thanks for this useful detail. I'll give it a try on Monday. I did > try a > similar idea, putting the current font name into another module which I > called > basefont.py. I built a test app and was able to change the font this > way (the > user has to quit and restart the app, but that's okay). The strange > thing is, > when I copy the methods into my real app, it doesn't work due to a > scoping > problem in the lambda function I use. I'll post the details on that on > Monday. > You could try this little snippet...: from Tkinter import * class WidgetWalker: def __init__(self, parent): self.parent = parent def __call__(self): self.walk(self.parent) def update(self, widget): try: widget["font"] = "Helvetica 18" except: pass try: widget["fg"] = "pink" except: pass def walk(self, top): self.update(top) for child in top.children.values(): self.walk(child) if __name__=="__main__": root = Tk() f = Frame(root) l = Label(f, text="Label") l.pack() b = Button(f, text="Button", command=WidgetWalker(root)) b.pack() inf = Frame(f) l2 = Label(inf, text="Label 2") l2.pack() inf2 = Frame(inf) l3 = Label(inf2, text="Label 3") l3.pack() inf2.pack() inf.pack() f.pack() root.mainloop() It relys on the children dictionary every Tkinter widget has. Cheers Martin From jepler at unpythonic.net Sat Sep 11 19:30:08 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sat Sep 11 19:30:25 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: <1094874813.414276bdbbbbe@midtoad.homelinux.org> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> Message-ID: <20040911173007.GA24310@unpythonic.net> On Fri, Sep 10, 2004 at 09:53:33PM -0600, stewart@midtoad.homelinux.org wrote: > I want to change all my menu entries to use the new font. But,I don't see how > to get the right name for those items to use in the list since each menu entry > doesn't have a discrete object name, like say a button would > (btn=Tkinter.Button, so you could have widgetlist=[btn,lbl,btn2]. I read > something about using component() to achieve this, but the exact implementation > escapes me - the example I saw related to notebook tabs rather than menu entries. > You'll have to use the "entryconfigure" method of the menu object. Here's a program that changes the font of all entries of a menu: import Tkinter def set_menu_font(m, f): for i in range(m.index("end") + 1): t = m.type(i) if t in ("tearoff", "separator"): continue # no font= option m.entryconfigure(i, font=f) t = Tkinter.Tk() m = Tkinter.Menu(t) t.configure(menu=m) m.insert_cascade("end", label="File", underline=0) m.insert_cascade("end", label="Edit", underline=0) m.insert_cascade("end", label="Help", underline=0) b = Tkinter.Button(t, command=lambda: set_menu_font(m, ("Helvetica", 24)), text="Font 1") c = Tkinter.Button(t, command=lambda: set_menu_font(m, ("Courier", 12)), text="Font 2") b.pack(side="left") c.pack(side="left") t.mainloop() -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040911/29baf482/attachment.pgp From stewart at midtoad.homelinux.org Tue Sep 14 02:23:05 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Tue Sep 14 02:22:01 2004 Subject: [Tkinter-discuss] How to change font sizes in a Tkinter app In-Reply-To: <20040911173007.GA24310@unpythonic.net> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> Message-ID: <1095121385.414639e921eb2@midtoad.homelinux.org> I posted a question on this topic a few days, and got three interesting, and quite varied, approaches to a solution from Jeff Epler, Martin Franklin and Michael Lange. One of the approaches apparently works under Linux, but wouldn't work (for me) under Windows, at least not yet. I had the most success adopting Martin's approach, which is contained in modified form in the code sample below. Note that my sample app makes use of Pmw, which you can get from http://pmw.sf.net. My app allows the user to change the font face or the font colour interactively. I leave it as an exercise for the reader to be able to change the font face as well (e.g. from Helvetica to Roman or Courier). This list is invaluable for me, because I'm coming across material that seems to be absent from any of the information sources I have so far for Tkinter. thanks again! cheers Stewart --- #MenuBarFontApp.py title = 'FontChange demonstration' # Import Pmw from this directory tree. import sys sys.path[:0] = ['../../..'] import Tkinter import Pmw class Demo: def __init__(self, parent): self.font=('Helvetica', 10, 'normal') print 'base font is ', self.font # 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') menuBar.addmenu('Options', 'Set general app options', font=self.font) menuBar.addcascademenu('Options', 'Font Size', 'Change global fonts', traverseSpec = 'z', tearoff = 1, font=self.font) for size in ('tiny', 'small', 'average', 'big', 'huge', 'monstrous'): menuBar.addmenuitem('Font Size', 'command', 'Set size to ' + size, command = lambda ss=size: WidgetWalker(ss), font=self.font, label = size) menuBar.addcascademenu('Options', 'Font Colour', 'Change global fonts', traverseSpec = 'z', tearoff = 1, font=self.font) for colour in ('black', 'blue', 'red', 'green', 'grey', 'brown'): menuBar.addmenuitem('Font Colour', 'command', 'Set size to ' + colour, command = lambda ss=colour: WidgetWalker2(ss), font=self.font, label = colour) # 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) class PrintOne: def __init__(self, text): self.text = text def __call__(self): print self.text #set font size class WidgetWalker: def __init__(self,size): self.parent = root # parent self.size = size 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.newFont = newFont self.walk(self.parent) def update(self, widget): try: widget["font"] = self.newFont[self.size] except: pass def walk(self, top): self.update(top) for child in top.children.values(): print 'child is ', child self.walk(child) #set font colour class WidgetWalker2: def __init__(self,colour): self.parent = root # parent self.colour = colour self.walk(self.parent) def update(self, widget): try: widget["fg"] = self.colour except: pass def walk(self, top): self.update(top) for child in top.children.values(): print 'child is ', child self.walk(child) ###################################################################### # 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() From mfranklin1 at gatwick.westerngeco.slb.com Tue Sep 14 09:45:22 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Sep 14 09:50:51 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> Message-ID: On Mon, 13 Sep 2004 18:23:05 -0600, wrote: > I posted a question on this topic a few days, and got three interesting, > and > quite varied, approaches to a solution from Jeff Epler, Martin Franklin > and > Michael Lange. One of the approaches apparently works under Linux, but > wouldn't > work (for me) under Windows, at least not yet. I had the most success > adopting > Martin's approach, which is contained in modified form in the code > sample below. > Note that my sample app makes use of Pmw, which you can get from > http://pmw.sf.net. My app allows the user to change the font face or > the font > colour interactively. I leave it as an exercise for the reader to be > able to > change the font face as well (e.g. from Helvetica to Roman or Courier). > > This list is invaluable for me, because I'm coming across material that > seems to > be absent from any of the information sources I have so far for Tkinter. > > thanks again! > > cheers > Stewart > Stewart, I got your code running good work! However it doesn't update the fonts of the menu items. At least not on my Windows machine - Win 2000 Python 2.3.3 For that I had to add some of Jeffs code see below > > > > --- > #MenuBarFontApp.py > > title = 'FontChange demonstration' > > # Import Pmw from this directory tree. > import sys > sys.path[:0] = ['../../..'] > > import Tkinter > import Pmw > > class Demo: > def __init__(self, parent): > > self.font=('Helvetica', 10, 'normal') > print 'base font is ', self.font > # 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') > > menuBar.addmenu('Options', 'Set general app options', font=self.font) > > menuBar.addcascademenu('Options', 'Font Size', > 'Change global fonts', traverseSpec = 'z', tearoff = 1, font=self.font) > for size in ('tiny', 'small', 'average', 'big', 'huge', 'monstrous'): > menuBar.addmenuitem('Font Size', 'command', 'Set size to ' + size, > command = lambda ss=size: WidgetWalker(ss), > font=self.font, > label = size) > > menuBar.addcascademenu('Options', 'Font Colour', > 'Change global fonts', traverseSpec = 'z', tearoff = 1, font=self.font) > for colour in ('black', 'blue', 'red', 'green', 'grey', 'brown'): > menuBar.addmenuitem('Font Colour', 'command', 'Set size to ' > + colour, > command = lambda ss=colour: > WidgetWalker2(ss), > font=self.font, > label = colour) > > # 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) > > class PrintOne: > def __init__(self, text): > self.text = text > > def __call__(self): > print self.text > > #set font size > class WidgetWalker: > def __init__(self,size): > self.parent = root # parent > self.size = size > 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.newFont = newFont > self.walk(self.parent) > > def update(self, widget): > try: > widget["font"] = self.newFont[self.size] > except: > pass ## extra try: except: block for menu items try: # for each menu item try setting the font for i in range(widget.index("end") + 1): t = widget.type(i) if t in ("tearoff", "separator"): ## unles it's a tearoff or separator continue widget.entryconfigure(i, font=self.newFont[self.size]) except: pass Cheers Martin > > def walk(self, top): > self.update(top) > for child in top.children.values(): > print 'child is ', child > self.walk(child) > > #set font colour > class WidgetWalker2: > def __init__(self,colour): > self.parent = root # parent > self.colour = colour > self.walk(self.parent) > > def update(self, widget): > try: > widget["fg"] = self.colour > except: > pass > > def walk(self, top): > self.update(top) > for child in top.children.values(): > print 'child is ', child > self.walk(child) > > > > ###################################################################### > > # 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() -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From Cameron at Phaseit.net Tue Sep 14 13:39:06 2004 From: Cameron at Phaseit.net (Cameron Laird) Date: Tue Sep 14 13:39:30 2004 Subject: [Tkinter-discuss] How to change font sizes in a Tkinter app In-Reply-To: <1095121385.414639e921eb2@midtoad.homelinux.org> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> Message-ID: <20040914113906.GA27926@lairds.us> On Mon, Sep 13, 2004 at 06:23:05PM -0600, stewart@midtoad.homelinux.org wrote: . . . > I posted a question on this topic a few days, and got three interesting, and > quite varied, approaches to a solution from Jeff Epler, Martin Franklin and > Michael Lange. One of the approaches apparently works under Linux, but wouldn't > work (for me) under Windows, at least not yet. I had the most success adopting > Martin's approach, which is contained in modified form in the code sample below. > Note that my sample app makes use of Pmw, which you can get from > http://pmw.sf.net. My app allows the user to change the font face or the font > colour interactively. I leave it as an exercise for the reader to be able to > change the font face as well (e.g. from Helvetica to Roman or Courier). > > This list is invaluable for me, because I'm coming across material that seems to > be absent from any of the information sources I have so far for Tkinter. > > thanks again! . . . The best thanks, folks, is to memorialize discoveries and creations in the Tkinter Wiki associated with this mailing list. While I make occasional abortive efforts to transfer knowledge there, it'll work a WHOLE lot better when several more of us are doing so. From jepler at unpythonic.net Tue Sep 14 15:12:51 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue Sep 14 15:12:55 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? Message-ID: <20040914131248.GL20186@unpythonic.net> I had intended to send this to the list, but I didn't. ----- Forwarded message from Jeff Epler ----- Date: Tue, 14 Sep 2004 06:54:29 -0500 From: Jeff Epler To: stewart@midtoad.homelinux.org Subject: Re: How to change font sizes in a Tkinter app? My menu manpage says this about menus on Windows: When Tk sees a System menu on Windows, its items are appended to the system menu that the menubar is attached to. This menu has an icon rep- resenting a spacebar, and can be invoked with the mouse or by typing Alt+Spacebar. Due to limitations in the Windows API, any font changes, colors, images, bitmaps, or tearoff images will not appear in the sys- tem menu. maybe this limitation applies to all menus, or the initial -font setting cannot change, or there is some OS-specific limitation that is not documented. This is the price you pay for a native-looking menu on Windows... I just ran this on Windows XP SP2, Python 2.3, Tk 8.4 and indeed my program doesn't work---the font doesn't change size. But neither does setting a font in the first place. When the menu with entry fonts set is posted by a menubutton, I get that font on Windows. mb = Tkinter.Menubutton(t, text="Menu") mbm = Tkinter.Menu(mb) mbm.insert_cascade("end", label="File", underline=0, font=("Helvetica", 24)) mbm.insert_cascade("end", label="Edit", underline=0) mbm.insert_cascade("end", label="Help", underline=0) mb.configure(menu=mbm) mb.pack(side="left") So I guess that items on the main menu bar have the same caveat as those on the System menu. It's unfortunate that this isn't documented by the Tk folks. Jeff ----- End forwarded message ----- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040914/ce619109/attachment.pgp From jepler at unpythonic.net Tue Sep 14 15:47:55 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue Sep 14 15:48:06 2004 Subject: [Tkinter-discuss] How to change font sizes in a Tkinter app In-Reply-To: <20040914113906.GA27926@lairds.us> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <20040914113906.GA27926@lairds.us> Message-ID: <20040914134755.GM20186@unpythonic.net> On Tue, Sep 14, 2004 at 11:39:06AM +0000, Cameron Laird wrote: > The best thanks, folks, is to memorialize discoveries and creations in > the Tkinter Wiki > associated with this mailing list. While I make occasional abortive > efforts to transfer knowledge there, it'll work a WHOLE lot better when > several more of us are doing so. In fact, I've used this as an excuse to create the page http://tkinter.unpythonic.net/wiki/Widgets/Menu Feel free to add to it if you have more to say! Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040914/06ae2743/attachment.pgp From mfranklin1 at gatwick.westerngeco.slb.com Tue Sep 14 16:58:16 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Sep 14 16:58:20 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? References: <20040914131248.GL20186@unpythonic.net> Message-ID: On Tue, 14 Sep 2004 08:12:51 -0500, Jeff Epler wrote: > I had intended to send this to the list, but I didn't. > > ----- Forwarded message from Jeff Epler ----- > Date: Tue, 14 Sep 2004 06:54:29 -0500 > From: Jeff Epler > To: stewart@midtoad.homelinux.org > Subject: Re: How to change font sizes in a Tkinter app? > > My menu manpage says this about menus on Windows: > When Tk sees a System menu on Windows, its items are appended > to the > system menu that the menubar is attached to. This menu has an > icon rep- > resenting a spacebar, and can be invoked with the mouse or by > typing > Alt+Spacebar. Due to limitations in the Windows API, any font > changes, > colors, images, bitmaps, or tearoff images will not appear in > the sys- > tem menu. > maybe this limitation applies to all menus, or the initial -font > setting cannot change, or there is some OS-specific limitation that is > not documented. This is the price you pay for a native-looking menu > on Windows... > > I just ran this on Windows XP SP2, Python 2.3, Tk 8.4 and indeed my > program doesn't work---the font doesn't change size. But neither does > setting a font in the first place. When the menu with entry fonts set > is posted by a menubutton, I get that font on Windows. > mb = Tkinter.Menubutton(t, text="Menu") > mbm = Tkinter.Menu(mb) > mbm.insert_cascade("end", label="File", underline=0, > font=("Helvetica", 24)) > mbm.insert_cascade("end", label="Edit", underline=0) > mbm.insert_cascade("end", label="Help", underline=0) > mb.configure(menu=mbm) > mb.pack(side="left") > Above does work - but I thought we were supposed to move away from Menubutton's (Can't remember where I read that though) > So I guess that items on the main menu bar have the same caveat as those > on the System menu. It's unfortunate that this isn't documented by the > Tk folks. > Sorry Jeff not sure I follow are you saying this : import Tkinter t = Tkinter.Tk() mb = Tkinter.Menu(t) mbm = Tkinter.Menu(mb) mbm.insert_cascade("end", label="File", underline=0, font=("Helvetica", 24)) mbm.insert_cascade("end", label="Edit", underline=0) mbm.insert_cascade("end", label="Help", underline=0) t["menu"] = mb mb.add_cascade(menu=mbm, label="Menu") t.mainloop() does not show a different font on your Windows system? > Jeff > ----- End forwarded message ----- -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From stewart at midtoad.homelinux.org Tue Sep 14 17:27:23 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Tue Sep 14 17:34:40 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: References: <20040914131248.GL20186@unpythonic.net> Message-ID: <1095175643.41470ddb0e603@midtoad.homelinux.org> Quoting Martin Franklin : > Sorry Jeff not sure I follow are you saying this : .. snip code sample ... > does not show a different font on your Windows system? I confess I'm confused by that as well. When I check your code sample, I see that the 'File' menu item is indeed in a larger font size. And indeed, if I modify that sample (see below) to add a font specification for every item in the menu, they all take a new font - except for the top-level menu item ("Menu"). Perhaps that's what Jeff means. With the app that I posted a little while ago, every level of my menubar takes a new font *except* for the system menu - but since the system menu is not normally used in running an app, I don't mind that. cheers S ---- import Tkinter import sys myFont = ("Helvetica", 18) t = Tkinter.Tk() mb = Tkinter.Menu(t, font=myFont) mbm = Tkinter.Menu(mb, font=myFont) mbm.insert_cascade("end", label="File", underline=0, font=myFont) mbm.insert_cascade("end", label="Edit", underline=0, font=myFont) mbm.insert_cascade("end", label="Help", underline=0, font=myFont) mbm.insert_cascade("end", label="Quit", underline=0, font=myFont, command=lambda: sys.exit("Bye")) t["menu"] = mb mb.add_cascade(menu=mbm, label="Menu", font=myFont) t.mainloop() From jepler at unpythonic.net Tue Sep 14 18:04:09 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue Sep 14 18:04:16 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app? In-Reply-To: References: <20040914131248.GL20186@unpythonic.net> Message-ID: <20040914160409.GN20186@unpythonic.net> Jeff wrote: > >So I guess that items on the main menu bar have the same caveat as those > >on the System menu. It's unfortunate that this isn't documented by the > >Tk folks. > > > > On Tue, Sep 14, 2004 at 03:58:16PM +0100, Martin Franklin wrote: > Sorry Jeff not sure I follow are you saying this : [snip] I don't have a Windows machine to test on at the moment, and it's possible that I botched my test code in the message. What I observed was that * If a menu is the -menu of a Toplevel, font settings are ignored on Windows * If a menu is the -menu of a Menubutton, font settings are obeyed on Windows I did not test the case for "cascade"s of the menubar, but I suspect that *will* show the changed font on Windows. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040914/579a56d2/attachment.pgp From stewart at midtoad.homelinux.org Tue Sep 14 17:10:48 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Tue Sep 14 18:10:46 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app In-Reply-To: References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> Message-ID: <1095174648.414709f826ca1@midtoad.homelinux.org> Quoting Martin Franklin : > I got your code running good work! However it doesn't update the fonts > of the menu items. > At least not on my Windows machine - Win 2000 Python 2.3.3 > For that I had to add some of Jeffs code see below Now this gets curioser and curioser. When I add your code in, the top-level menu entries (File, Options) no longer change fonts. (Maybe I copied or indented your code wrong?). If I leave my test app as-is, all of the menu items' fonts change. I'll attach my app as an attachment so it retains its formatting, though a text version is below, for those that don't get attachments. My code for the update method comes first, with yours as a new method update2; switching the names will run your version instead of mine. Do you get the same results as I do when you run this app? BTW I'm running Win2k and Python 2.3.4, nearly the same configuration as yours. cheers S -------------- next part -------------- title = 'FontChange demonstration' # Import Pmw from this directory tree. import sys sys.path[:0] = ['../../..'] import Tkinter import Pmw class Demo: def __init__(self, parent): self.font=('Helvetica', 10, 'normal') print 'base font is ', self.font # 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') menuBar.addmenu('Options', 'Set general app options', font=self.font) menuBar.addcascademenu('Options', 'Font Size', 'Change global fonts', traverseSpec = 'z', tearoff = 1, font=self.font) for size in ('tiny', 'small', 'average', 'big', 'huge', 'monstrous'): menuBar.addmenuitem('Font Size', 'command', 'Set size to ' + size, command = lambda ss=size: WidgetWalker(ss), font=self.font, label = size) menuBar.addcascademenu('Options', 'Font Colour', 'Change global fonts', traverseSpec = 'z', tearoff = 1, font=self.font) for colour in ('black', 'blue', 'red', 'green', 'grey', 'brown'): menuBar.addmenuitem('Font Colour', 'command', 'Set size to ' + colour, command = lambda ss=colour: WidgetWalker2(ss), font=self.font, label = colour) # 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) class PrintOne: def __init__(self, text): self.text = text def __call__(self): print self.text #set font size class WidgetWalker: def __init__(self,size): self.parent = root # parent self.size = size 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.newFont = newFont self.walk(self.parent) def update(self, widget): try: widget["font"] = self.newFont[self.size] except: pass def update2(self, widget): try: # for each menu item try setting the font for i in range(widget.index("end") + 1): t = widget.type(i) ## unless it's a tearoff or separator if t in ("tearoff", "separator"): continue widget.entryconfigure(i, font=self.newFont[self.size]) except: pass def walk(self, top): self.update(top) for child in top.children.values(): print 'child is ', child self.walk(child) #set font colour class WidgetWalker2: def __init__(self,colour): self.parent = root # parent self.colour = colour self.walk(self.parent) def update2(self, widget): try: widget["fg"] = self.colour except: pass def walk(self, top): self.update(top) for child in top.children.values(): print 'child is ', child self.walk(child) ###################################################################### # 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() From mfranklin1 at gatwick.westerngeco.slb.com Tue Sep 14 18:26:59 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Sep 14 18:27:04 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <1095174648.414709f826ca1@midtoad.homelinux.org> Message-ID: On Tue, 14 Sep 2004 09:10:48 -0600, wrote: > Quoting Martin Franklin : > >> I got your code running good work! However it doesn't update the fonts >> of the menu items. >> At least not on my Windows machine - Win 2000 Python 2.3.3 >> For that I had to add some of Jeffs code see below > > Now this gets curioser and curioser. When I add your code in, the > top-level > menu entries (File, Options) no longer change fonts. (Maybe I copied or > indented > your code wrong?). If I leave my test app as-is, all of the menu items' > fonts > change. I'll attach my app as an attachment so it retains its > formatting, > though a text version is below, for those that don't get attachments. > My code > for the update method comes first, with yours as a new method update2; > switching > the names will run your version instead of mine. Do you get the same > results > as I do when you run this app? > > BTW I'm running Win2k and Python 2.3.4, nearly the same configuration as > yours. > > cheers > S Stewart, Unchanged your code does update the font of the Menu-bars items (I.E The words "File" + "Options") but not the menu items. I just had a thought perhaps it's a different Pmw version..... ahhh yes I've got an old 0.8.3 Pmw Bundle in my dumping ground directory! This version of Pmw uses Menubuttons (under the covers|) perhaps the latest is different... I will need to download and install (should have done that years ago) Incidentally I am also using Python 2.3.4 - I Must have upgraded in my sleep ;-) Will let you know after the upgrade... Cheers, Martin. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From mfranklin1 at gatwick.westerngeco.slb.com Tue Sep 14 18:30:20 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Sep 14 18:40:52 2004 Subject: [Tkinter-discuss] Tkinter Wiki Was: Re: How to change font sizes in a Tkinter app References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <20040914113906.GA27926@lairds.us> Message-ID: On Tue, 14 Sep 2004 11:39:06 +0000, Cameron Laird wrote: > On Mon, Sep 13, 2004 at 06:23:05PM -0600, stewart@midtoad.homelinux.org > wrote: > . > . > . >> I posted a question on this topic a few days, and got three >> interesting, and >> quite varied, approaches to a solution from Jeff Epler, Martin Franklin >> and >> >> thanks again! > . > . > . > The best thanks, folks, is to memorialize discoveries and creations in > the Tkinter Wiki > associated with this mailing list. While I make occasional abortive > efforts to transfer knowledge there, it'll work a WHOLE lot better when > several more of us are doing so. And on that note I just updated the Widgets Page to include a mention of the new widgets in Tk 8.4, now that I have broadband at home I hope to be able to provide more information to the Wiki :-) I also added a short note regarding TkTable As for the recipe (WidgetWalker) where abouts should it go - It ain't a new Widget;-) Martin -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From mfranklin1 at gatwick.westerngeco.slb.com Tue Sep 14 18:52:45 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Sep 14 18:52:51 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <1095174648.414709f826ca1@midtoad.homelinux.org> Message-ID: On Tue, 14 Sep 2004 17:26:59 +0100, Martin Franklin wrote: > On Tue, 14 Sep 2004 09:10:48 -0600, > wrote: > >> Quoting Martin Franklin : >> >>> I got your code running good work! However it doesn't update the fonts >> >> Now this gets curioser and curioser. When I add your code in, the >> top-level > > Unchanged your code does update the font of the Menu-bars items > (I.E The words "File" + "Options") but not the menu items. > > I just had a thought perhaps it's a different Pmw version..... ahhh > yes I've got an old 0.8.3 Pmw Bundle in my dumping ground directory! > This version of Pmw uses Menubuttons (under the covers|) perhaps the > latest is different... > > I will need to download and install (should have done that years ago) > > Incidentally I am also using Python 2.3.4 - I Must have upgraded in my > sleep ;-) > > Will let you know after the upgrade... Well now I'm stumped... really running your code unchanged with Python 2.3.4 on Windows 2000 with Pmw 1.2 it only changes the Toplevel Menu Font "File" and "Options" none of the menu items change font at all Then, again unchanged, using update2 method does the oposite - it changes the fonts of all the menu items but not the toplevel menu's themselves Now I put the update code into the update2 method (as I think it was in my earlier reply) and it changes all fonts for all menu's and all menu items. Lets call it update3 ;-) def update3(self, widget): try: widget["font"] = self.newFont[self.size] except: pass try: # for each menu item try setting the font for i in range(widget.index("end") + 1): t = widget.type(i) ## unless it's a tearoff or separator if t in ("tearoff", "separator"): continue widget.entryconfigure(i, font=self.newFont[self.size]) except: pass I had a quick look at the Pmw source code for it's MenuBar and it still uses Menubutton under the covers, however I noticed a MainMenuBar mega widget that does not... I think part of all the confusion lies with the Menubutton vs Menu widget in Tkinter... As I said in an earlier post I thought Menubutton was depricated - I can't remember when or where I read that - I thought it was in Guido's old tkinter demo code that used to ship with the python source code (anyone got an old distro?) but my memory's not what it used to be (2 kids will do that to a man) Clear as mud ;-) Cheers Martin -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From mfranklin1 at gatwick.westerngeco.slb.com Tue Sep 14 19:18:55 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Sep 14 19:19:01 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <1095174648.414709f826ca1@midtoad.homelinux.org> Message-ID: [snip] > widget that does not... I think part of all the confusion lies with > the Menubutton vs Menu widget in Tkinter... As I said in an earlier Bingo! Jeff has been right all along - I just wouldn't listen ;-) If the Toplevel menu is a Menu object then the font option is ignored on windows it's items font may be set though. If however Menubutton is used then the font option is honoured. Pmw.MenuBar uses Menubutton > post I thought Menubutton was depricated - I can't remember when or As for that I guess my brain really is fried! [snip useless babble from myself] So Stewart what was the question again? ;-) -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From jepler at unpythonic.net Tue Sep 14 21:00:55 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue Sep 14 21:01:02 2004 Subject: [Tkinter-discuss] Tkinter Wiki Was: Re: How to change font sizes in a Tkinter app In-Reply-To: References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <20040914113906.GA27926@lairds.us> Message-ID: <20040914190055.GQ20186@unpythonic.net> > As for the recipe (WidgetWalker) where abouts should it go - It ain't a > new Widget;-) A separate Recipes page seems appropriate to me. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040914/c0d44584/attachment.pgp From stewart at midtoad.homelinux.org Wed Sep 15 04:44:44 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Wed Sep 15 04:42:29 2004 Subject: [Tkinter-discuss] Re: How to change font sizes in a Tkinter app In-Reply-To: References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <1095174648.414709f826ca1@midtoad.homelinux.org> Message-ID: <1095216284.4147ac9cd6dd8@midtoad.homelinux.org> Quoting Martin Franklin : > If the Toplevel menu is a Menu object then the font option is ignored > on windows it's items font may be set though. > > If however Menubutton is used then the font option is honoured. > > Pmw.MenuBar uses Menubutton I'll bet you can't find this kind of useful detail in most of the tutorials. And it's exactly those little details that trip you up when attempting something new. Which is why a recipe collection of how-tos for typical tasks is a good idea. cheers Stewart From mfranklin1 at gatwick.westerngeco.slb.com Wed Sep 15 09:49:44 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed Sep 15 09:51:28 2004 Subject: [Tkinter-discuss] Tkinter Wiki Was: Re: How to change font sizes in a Tkinter app In-Reply-To: <20040914190055.GQ20186@unpythonic.net> References: <5F063358AA124D43AE65BE83F89A01622FCD0C@sbpnt6.shields.com> <1094831785.4141cea9e2c77@midtoad.homelinux.org> <1094839024.4141eaf0be284@midtoad.homelinux.org> <1094854050.414225a2e7b5a@midtoad.homelinux.org> <20040911023705.001a4122.klappnase@freenet.de> <1094874813.414276bdbbbbe@midtoad.homelinux.org> <20040911173007.GA24310@unpythonic.net> <1095121385.414639e921eb2@midtoad.homelinux.org> <20040914113906.GA27926@lairds.us> <20040914190055.GQ20186@unpythonic.net> Message-ID: On Tue, 14 Sep 2004 14:00:55 -0500, Jeff Epler wrote: >> As for the recipe (WidgetWalker) where abouts should it go - It ain't a >> new Widget;-) > A separate Recipes page seems appropriate to me. > > Jeff Thanks Jeff, Done. I also attempted to re-word you explanation of the whole Menu episode ;-) I added a ExampleCompoundButton and wanted to include an image. I could like from my own website but I guess it would be faster to have a local link. In fact I did want to add images of the new 8.4 widgets too. Cheers Martin From clnethery at juno.com Tue Sep 21 04:38:54 2004 From: clnethery at juno.com (Chris Nethery) Date: Tue Sep 21 04:39:39 2004 Subject: [Tkinter-discuss] String-names and the NoteBook entryfield Message-ID: <20040920.193900.10145.187701@webmail07.nyc.untd.com> Hello everyone. I have an issue that is causing me many anxious moments. So, at long last, I feel I need to refer to the experts. I am trying to create a Pmw.NoteBook instance that the user names as he/she creates it. Specifically, I am trying to enable the user to name the NoteBook instance in its own entryfield, similar to creating a new Tree node in Windows Explorer or a new Windows folder or shortcut icon, for example. Secondly, I am having a hard time associating the input string name with the NoteBook instance. Unfortunately, I have gone through many cycles trying to make things work, and the code has broken each time, so I have included just the base code that (almost) works. Any ideas on this one? Thanking you in advance, Christopher Nethery ### imports ### from Tkinter import * from Tkconstants import * import Pmw ### initialization ### root = Tk() root.wm_geometry("1015x705") Pmw.initialise(root) ### notebooks ### class MyWidgets: def __init__(self, root): self.root = root Mainframe = Frame(self.root) Mainframe.pack(fill='both', expand=1, padx=1, pady=1) self.Notebook = Pmw.NoteBook(Mainframe, createcommand=self.curse_Selection) self.Notebook.pack(fill='both', expand=1, padx=1, pady=1) self.nameEntryField = Pmw.EntryField(self.Notebook.tab(""), label_font=(('Verdana'), '7'), labelpos=W, labelmargin=0, label_text='Stuff:') self.nameEntryField.pack(fill='both', expand=1, padx=1, pady=1) fieldEntry = self.nameEntryField.component('entry').get() self.NotebookPage1 = self.Notebook.add(fieldEntry) self.NotebookPage1.pack(fill='both', expand=1, padx=1, pady=1) self.NotebookPage1Frame = Frame(self.NotebookPage1, borderwidth=2, width=975, height=650, relief=GROOVE) self.NotebookPage1Frame.pack(fill='both', expand=1, padx=1, pady=1) def curse_Selection(self, notebook): pass if __name__=='__main__': mw = MyWidgets(root) root.mainloop() From PeterM at resmed.com.au Tue Sep 21 06:15:24 2004 From: PeterM at resmed.com.au (Peter Milliken) Date: Tue Sep 21 06:15:36 2004 Subject: [Tkinter-discuss] String-names and the NoteBook entryfield Message-ID: <274A369893F5FB4099345F006439D9870316C410@bella.corp.resmed.org> Hi Chris, Each notebook "page" is created using an instance of tkinter.Frame and tkinter.Button (according to the reference page for NoteBook). So your first problem would be that "buttons" can't be typed into - you need to replace the Button component of each page with an EntryField -> which changes to an grayed out entryfield (or something similar) once the user has supplied the name. So (re)searching back into the class hierachy reveals that classes derived from Pmw.MegaArchType's can have the "default" components from which they are built "overridden" (refer to the "pyclass component option" section of Pmw.MegaArchType). There are some "clues" here as to what you might have to do - perhaps examine the code of NoteBook and then create a class that inherits from NoteBook - which uses an entry widget of some form in the construction of a new page and then either changes it to "Button" or "greys" it out so it can't be changed after the user has supplied the name. Certainly that is how I would proceed - inherit from NoteBook and create a new class that offers this "feature" - you'll then have a nice re-usable component that you could share with the rest of us :-) At first glance it is a non-trivial exercise i.e. more time than I have left in my lunch hour to nut this one out :-) So goodluck with your journey. Peter > -----Original Message----- > From: Chris Nethery [mailto:clnethery@juno.com] > Sent: Tuesday, September 21, 2004 12:39 PM > To: tkinter-discuss@python.org > Subject: [Tkinter-discuss] String-names and the NoteBook entryfield > > > > Hello everyone. I have an issue that is causing me many > anxious moments. So, at long last, I feel I need to refer to > the experts. > > I am trying to create a Pmw.NoteBook instance that the user > names as he/she creates it. Specifically, I am trying to > enable the user to name the NoteBook instance in its own > entryfield, similar to creating a new Tree node in Windows > Explorer or a new Windows folder or shortcut icon, for > example. Secondly, I am having a hard time associating the > input string name with the NoteBook instance. Unfortunately, > I have gone through many cycles trying to make things work, > and the code has broken each time, so I have included just > the base code that (almost) works. Any ideas on this one? > > Thanking you in advance, > > > Christopher Nethery > > > > ### imports ### > > from Tkinter import * > from Tkconstants import * > import Pmw > > ### initialization ### > > root = Tk() > root.wm_geometry("1015x705") > Pmw.initialise(root) > > > ### notebooks ### > > class MyWidgets: > > def __init__(self, root): > > self.root = root > > Mainframe = Frame(self.root) > Mainframe.pack(fill='both', expand=1, padx=1, pady=1) > > self.Notebook = Pmw.NoteBook(Mainframe, > createcommand=self.curse_Selection) > self.Notebook.pack(fill='both', expand=1, padx=1, pady=1) > > self.nameEntryField = > Pmw.EntryField(self.Notebook.tab(""), > label_font=(('Verdana'), '7'), labelpos=W, labelmargin=0, > label_text='Stuff:') > self.nameEntryField.pack(fill='both', expand=1, > padx=1, pady=1) > fieldEntry = self.nameEntryField.component('entry').get() > > self.NotebookPage1 = self.Notebook.add(fieldEntry) > self.NotebookPage1.pack(fill='both', expand=1, padx=1, pady=1) > > self.NotebookPage1Frame = Frame(self.NotebookPage1, > borderwidth=2, width=975, height=650, relief=GROOVE) > self.NotebookPage1Frame.pack(fill='both', expand=1, > padx=1, pady=1) > > > def curse_Selection(self, notebook): > pass > > > > if __name__=='__main__': > mw = MyWidgets(root) > root.mainloop() > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > Warning: Copyright ResMed. Where the contents of this email and/or attachment includes materials prepared by ResMed, the use of those materials is subject exclusively to the conditions of engagement between ResMed and the intended recipient. This communication is confidential and may contain legally privileged information. By the use of email over the Internet or other communication systems, ResMed is not waiving either confidentiality of, or legal privilege in,the content of the email and of any attachments. If the recipient of this message is not the intended addressee, please call ResMed immediately on +61 2 9886 5000 Sydney, Australia. From clnethery at juno.com Wed Sep 22 03:24:23 2004 From: clnethery at juno.com (Chris Nethery) Date: Wed Sep 22 03:25:38 2004 Subject: [Tkinter-discuss] String-names and the NoteBook entryfield Message-ID: <20040921.182501.15747.737658@webmail10.nyc.untd.com> Peter, Thank you for some direction on this one. And, you're right, this will make a great GUI enhancement, once it's completed. I'd be happy to post the finished product in the forum, once finished, although I imagine I may need some more pointers here and there until it's complete. Best regards, Chris Nethery From mfranklin1 at gatwick.westerngeco.slb.com Wed Sep 22 09:21:09 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed Sep 22 09:21:17 2004 Subject: [Tkinter-discuss] Re: String-names and the NoteBook entryfield References: <20040920.193900.10145.187701@webmail07.nyc.untd.com> Message-ID: On Tue, 21 Sep 2004 02:38:54 GMT, Chris Nethery wrote: > > Hello everyone. I have an issue that is causing me many anxious > moments. So, at long last, I feel I need to refer to the experts. > > I am trying to create a Pmw.NoteBook instance that the user names as > he/she creates it. Specifically, I am trying to enable the user to name > the NoteBook instance in its own entryfield, similar to creating a new > Tree node in Windows Explorer or a new Windows folder or shortcut icon, > for example. Secondly, I am having a hard time associating the input > string name with the NoteBook instance. Unfortunately, I have gone > through many cycles trying to make things work, and the code has broken > each time, so I have included just the base code that (almost) works. > Any ideas on this one? > > Thanking you in advance, > > > Christopher Nethery > > Chris, I snipped all your code sorry but here is my first stab at the problem you outlined from Tkinter import * import Pmw class MegaNoteBook(Frame): def __init__(self, parent): Frame.__init__(self) addButton = Button(self, text="Add Page", command=self.addPage) addButton.pack() self.noteBook = Pmw.NoteBook(self) self.noteBook.pack(fill="both", expand="yes") def addPage(self): ## method to add a page to the notebook - I need to change the 'button' tab ## property of the nbotebook thisPage = self.noteBook.add("NewPage") ## find the button widget for this page bind to thisTab = self.noteBook.tab("NewPage") ##it's text put up an entry field so the user can edit it self.update() x, y = thisTab.winfo_rootx(), thisTab.winfo_rooty() entry = MegaEntryField(x, y, self) def setNewPageName(self, name): print name class MegaEntryField(Toplevel): def __init__(self, topx, topy, megaNoteBook): Toplevel.__init__(self) self.overrideredirect(True) self.geometry("+%d+%d" %(topx, topy)) self.megaNoteBook = megaNoteBook self.entry = Pmw.EntryField(self, entry_width = 7, command=self.renamePage) self.entry.setentry("NewPage") self.entry.pack() ## ?? should size accordingly def renamePage(self): name = self.entry.get() self.megaNoteBook.setNewPageName(name) self.withdraw() root=Tk() mnb = MegaNoteBook(root) mnb.pack(fill="both", expand="yes") root.mainloop() -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From clnethery at juno.com Fri Sep 24 04:50:57 2004 From: clnethery at juno.com (Chris Nethery) Date: Fri Sep 24 04:52:20 2004 Subject: [Tkinter-discuss] Re: String-names and the NoteBook entryfield Message-ID: <20040923.195120.12675.777038@webmail13.nyc.untd.com> Martin, wow! That's exactly what I'm trying to accomplish. I can't wait to tinker with the code this evening! Thank you for your help! Sincerely, Chris Nethery From mfranklin1 at gatwick.westerngeco.slb.com Fri Sep 24 11:00:12 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Fri Sep 24 11:00:22 2004 Subject: [Tkinter-discuss] Re: Re: String-names and the NoteBook entryfield References: <20040923.195120.12675.777038@webmail13.nyc.untd.com> Message-ID: On Fri, 24 Sep 2004 02:50:57 GMT, Chris Nethery wrote: > > Martin, wow! That's exactly what I'm trying to accomplish. I can't > wait to tinker with the code this evening! Thank you for your help! > > Sincerely, > > > Chris Nethery Thanks Chris, Just a few words of warning regarding the Pmw.NoteBook it keeps track of its pages using both a list and dictionary I know from past experience changing the name of a NoteBook page causes a lot of headaches, I think (although I can't find the code) I ended up keeping track of 'new vs old' page names in my own code. Cheers Martin -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From David.Vaughan at Gifford.UK.com Fri Sep 24 13:01:25 2004 From: David.Vaughan at Gifford.UK.com (David Vaughan) Date: Fri Sep 24 12:59:18 2004 Subject: [Tkinter-discuss] py2exe and Pmw - help please Message-ID: I'm sure you've had this query before, and I did try lots of googling, but I still haven't got there... I have a program which uses Tkinter and Pmw, and it works fine in the interpreter. I have used py2exe succesfully on non-gui programs. And I have created Pmw.py using bundlepmw.py. But, wherever I put Pmw.py (and PmwBlt.py and PmwColor.py), I get the same message on running the executable as if I hadn'd bothered hooking up Pmw at all: Traceback (most recent call last): File "newproj.py", line 21, in ? File "Pmw\__init__.pyc", line 28, in ? WindowsError: [Errno 3] The system cannot find the path specified: 'C:\\data\\Software\\Python\\newproj\\v2_1\\dist\\library.zip\\Pmw/*.*' So, where do I put the Pmw files when I use py2exe? And also, once I've made my executable, what do I do with all the dll, pyd, and zip files when I use my executable on another computer? I'm using Python 2.3 and Windows XP for the compilation, and various flavours of Windows for running the executable. And here's my setup.py: #-------------- from distutils.core import setup import py2exe import sys sys.argv.append("py2exe") #Avoids having to use the command line setup( version = "2.1", description = "Creates default file structures for new projects/tenders", name = "newproj", ## packages = ["Pmw"], # targets to build windows = ["newproj.py"], ) #-------------- Any help would be most welcome. David David Vaughan Structural Analyst GIFFORD AND PARTNERS LTD Carlton House, Ringwood Road, Woodlands, Southampton, SO40 7HT, UNITED KINGDOM Tel: +44 (0)23 8081 7500 Fax: +44 (0)23 8081 7600 Email: David.Vaughan@gifford.uk.com Web: http://www.gifford.uk.com _____ This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed and may be confidential. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, be advised that you have received this e-mail in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. From stewart at midtoad.homelinux.org Sat Sep 25 02:26:07 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Sat Sep 25 02:21:21 2004 Subject: [Tkinter-discuss] passing parameters to a lambda function in Tkinter menubar Message-ID: <1096071967.4154bb1f13449@midtoad.homelinux.org> Here's a problem I keep running into. It occurs when I try to pass parameters to a menubar item's command property using a lambda function. Probably it's a scoping problem, but I don't see how to resolve it (except not to pass parameters). Essentially the problem is this: if you simply call a method as the command callback when you are creating a GUI, that command will be executed right away when the GUI is drawn - at least, if you pass that method any arguments. One way to get around this is not pass arguments to the callback methods. I thought another way might be to use a lambda function, and pass it the arguments. That works if the lambda calls another class, but if it calls a method in the same class, I get name errors. In the attached mini-app, which uses Pmw, the File > Close menu selection uses a lambda function that passes a parameter to another class with a __call__ method. It works properly. However, the Options > Set size To menu choice, which uses a lambda function to pass the size string to a setFont method, does not work. It looks as though the lambda function doesn't know it's part of the Demo class, so it can't find the self.setFont method. If I replace 'self' with the name of the class, Demo, I instead get an error saying 'unbound method must be called with class instance 1st argument'. Can anyone shed any light on how make this latter method work? It would greatly clean up my app. thanks Stewart -------------- next part -------------- title = 'FontSize demonstration' # Import Pmw from this directory tree. import sys sys.path[:0] = ['c:\\programs'] import Tkinter import tkFont import Pmw class Demo: def __init__(self, parent): self.font = ('Helvetica', 10) # 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: Demo.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: ',self.font #('tiny', 'small', 'average', 'big', 'huge') print 'new font: ', size 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() From fredrik at pythonware.com Sat Sep 25 08:55:40 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat Sep 25 08:53:42 2004 Subject: [Tkinter-discuss] Re: passing parameters to a lambda function inTkinter menubar References: <1096071967.4154bb1f13449@midtoad.homelinux.org> Message-ID: stewart@midtoad.homelinux.org wrote: > However, the Options > Set size To menu choice, which uses a lambda function to > pass the size string to a setFont method, does not work. It looks as though the > lambda function doesn't know it's part of the Demo class, so it can't find the > self.setFont method. If I replace 'self' with the name of the class, Demo, I > instead get an error saying 'unbound method must be called with class instance > 1st argument'. the lambda isn't part of the class, it's a function object. to be able to find the right self, bind it just like you bind the size value. menuBar.addmenuitem('Size', 'command', 'Set size to ' + size, command = lambda self=self, ss=size: self.setFont(ss), font=self.font, label = size) according to the "functions are cheap, lambdas are hard to read" rule, this is better written as: def setfontsize(self=self, size=size): self.setFont(size) menuBar.addmenuitem('Size', 'command', 'Set size to ' + size, command = setfontsize, font=self.font, label = size) also see: http://groups.google.com/groups?selm=mailman.1011942158.19361.python-list%40python.org From stewart at midtoad.homelinux.org Sat Sep 25 18:17:58 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Sat Sep 25 18:13:37 2004 Subject: [Tkinter-discuss] Re: passing parameters to a lambda function inTkinter menubar In-Reply-To: References: <1096071967.4154bb1f13449@midtoad.homelinux.org> Message-ID: <1096129078.41559a36f16d6@midtoad.homelinux.org> Quoting Fredrik Lundh : > the lambda isn't part of the class, it's a function object. to be able to > find the right self, bind it just like you bind the size value. doh! That seems so obvious when you explain it. Naturally, though, that concept doesn't appear in any documentation I've read about lambda functions. > according to the "functions are cheap, lambdas are hard to read" rule, > this is better written as: > > def setfontsize(self=self, size=size): > self.setFont(size) > menuBar.addmenuitem('Size', 'command', 'Set size to ' + size, > command = setfontsize, font=self.font, label = size) This is great! It allows the code to be read more easily, while still allowing me to pass arguments through the callback. This great little tip should be on the tkinter wiki site (note to self). thanks again Stewart From Cameron at Phaseit.net Sat Sep 25 18:36:52 2004 From: Cameron at Phaseit.net (Cameron Laird) Date: Sat Sep 25 18:36:58 2004 Subject: [Tkinter-discuss] Re: passing parameters to a lambda function inTkinter menubar In-Reply-To: <1096129078.41559a36f16d6@midtoad.homelinux.org> References: <1096071967.4154bb1f13449@midtoad.homelinux.org> <1096129078.41559a36f16d6@midtoad.homelinux.org> Message-ID: <20040925163652.GA6447@lairds.us> On Sat, Sep 25, 2004 at 10:17:58AM -0600, stewart@midtoad.homelinux.org wrote: . . . > > the lambda isn't part of the class, it's a function object. to be able to > > find the right self, bind it just like you bind the size value. > > doh! That seems so obvious when you explain it. Naturally, though, that > concept doesn't appear in any documentation I've read about lambda functions. > > > according to the "functions are cheap, lambdas are hard to read" rule, > > this is better written as: > > > > def setfontsize(self=self, size=size): > > self.setFont(size) > > menuBar.addmenuitem('Size', 'command', 'Set size to ' + size, > > command = setfontsize, font=self.font, label = size) > > This is great! It allows the code to be read more easily, while still allowing > me to pass arguments through the callback. This great little tip should be on > the tkinter wiki site (note to self). . . . I think you're thinking of this in terms of syntactic scope. While that's a healthy instinct, the approach I find most successful in explaining Tkinter's event orientation is to teach developers to categorize variables in terms of "define-time" (or "bind-time") vs. "run-time" ("execute-time" or "use-time" or ...). IT CAN EASILY HAPPEN THAT ONE BINDING INCLUDES BOTH. I'm too weary now to write this up for the Wiki. I invite you to do so, though. From dblank at cs.brynmawr.edu Sun Sep 26 05:45:47 2004 From: dblank at cs.brynmawr.edu (dblank@cs.brynmawr.edu) Date: Sun Sep 26 05:45:55 2004 Subject: [Tkinter-discuss] Tkinter screen saver? Message-ID: Tkinter discussion, I'm wondering if I can get Tkinter to make a window that covers the whole screen so that we can have a Python-based screen saver? It looks like I can't move a Tkinter window so that the title bar doesn't show. For example, I see that Tkinter cleverly assumes that if I set a window geometry with negative x and/or y, it positions it from the bottom/right. But if I keep making the negative number bigger, I can get it to go off of the top of the window; I always get the title bar on the screen. Maybe this is my window manager's fault? Also, I can't make a window bigger than the screen size minus the width of the borders. Anyone have any ideas on getting something that approximates a canvas that covers the whole screen in Python? Thanks for any pointers, -Doug From clnethery at juno.com Sun Sep 26 06:11:37 2004 From: clnethery at juno.com (Chris Nethery) Date: Sun Sep 26 06:13:27 2004 Subject: [Tkinter-discuss] Re: Re: String-names and the NoteBook entryfield Message-ID: <20040925.211234.12675.798050@webmail13.nyc.untd.com> That makes sense to me. Thanks again! --Chris Nethery From fredrik at pythonware.com Sun Sep 26 09:53:38 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun Sep 26 09:51:39 2004 Subject: [Tkinter-discuss] Re: Tkinter screen saver? References: Message-ID: wrote: > I'm wondering if I can get Tkinter to make a window that covers the whole > screen so that we can have a Python-based screen saver? try this: from Tkinter import * root = Tk() root.config(bg="red") w, h = root.winfo_screenwidth(), root.winfo_screenheight() root.overrideredirect(1) root.geometry("%dx%d+0+0" % (w, h)) root.mainloop() From dblank at mainline.brynmawr.edu Mon Sep 27 16:37:04 2004 From: dblank at mainline.brynmawr.edu (Douglas S. Blank) Date: Mon Sep 27 17:12:54 2004 Subject: [Tkinter-discuss] Re: Tkinter screen saver? In-Reply-To: References: Message-ID: <41582590.3010504@cs.brynmawr.edu> Great! Had missed "overrideredirect". For anyone that is interested, this project is really a program that runs on a hall computer LCD display. It will no doubt change (become more dynamic/customizable), but it currently displays images from a directory and has a ticker that runs across the bottom. You can see the current source at: http://bubo.brynmawr.edu/cgi-bin/viewcvs.cgi/DisplayProject/display.py?rev=HEAD&content-type=text/vnd.viewcvs-markup Suggestions/comments always welcome. Thanks again, -Doug Fredrik Lundh wrote: > wrote: > > >>I'm wondering if I can get Tkinter to make a window that covers the whole >>screen so that we can have a Python-based screen saver? > > > try this: > > from Tkinter import * > > root = Tk() > root.config(bg="red") > > w, h = root.winfo_screenwidth(), root.winfo_screenheight() > root.overrideredirect(1) > root.geometry("%dx%d+0+0" % (w, h)) > > root.mainloop() > > > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- Douglas S. Blank, Assistant Professor dblank@brynmawr.edu, (610)526-6501 Bryn Mawr College, Computer Science Program 101 North Merion Ave, Park Science Bld. Bryn Mawr, PA 19010 dangermouse.brynmawr.edu From mfranklin1 at gatwick.westerngeco.slb.com Tue Sep 28 11:19:07 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Sep 28 11:19:18 2004 Subject: [Tkinter-discuss] Re: py2exe and Pmw - help please References: Message-ID: On Fri, 24 Sep 2004 12:01:25 +0100, David Vaughan wrote: > > I'm sure you've had this query before, and I did try lots of googling, > but I still haven't got there... > > I have a program which uses Tkinter and Pmw, and it works fine in the > interpreter. I have used py2exe > succesfully on non-gui programs. And I have created Pmw.py using > bundlepmw.py. But, wherever I put > Pmw.py (and PmwBlt.py and PmwColor.py), I get the same message on > running the executable as if I hadn'd > bothered hooking up Pmw at all: > > Traceback (most recent call last): > File "newproj.py", line 21, in ? > File "Pmw\__init__.pyc", line 28, in ? > WindowsError: [Errno 3] The system cannot find the path specified: > 'C:\\data\\Software\\Python\\newproj\\v2_1\\dist\\library.zip\\Pmw/*.*' > I guess one question would be how do you import Pmw in your application. I have created a Tkinter + Pmw py2exe application I didn't do anything special. I too had a Pmw.py and PmwColor.py bundle both these files are are in a sub-directory (and package) called Pmw, this package also has a __init__.py file. The contents of the __init__.py file are:- # __init__.py Pmw Package from Pmw import * The setup.py I used looked like this:- # setup.py from distutils.core import setup import py2exe setup(windows=["MyApplication.pyw"]) And it just worked.... Inside the main application module I import Pmw like so: import Pmw So again nothing special.... Sorry I can't be of more help.... Martin -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From David.Vaughan at Gifford.UK.com Tue Sep 28 12:23:18 2004 From: David.Vaughan at Gifford.UK.com (David Vaughan) Date: Tue Sep 28 12:21:15 2004 Subject: [Tkinter-discuss] Re: py2exe and Pmw - help please Message-ID: Thanks Martin, that worked. In fact I had been here before, amongst other variations. But the trick was to delete the "dist" folder before running setup.py. Martin Franklin wrote: > I guess one question would be how do you import Pmw in your application. I have created a Tkinter + Pmw py2exe > application I didn't do anything special. I too had a Pmw.py and PmwColor.py bundle both these files are are > in a sub-directory (and package) called Pmw, this package also has a __init__.py file. The contents of the > __init__.py file are:- > > > # __init__.py Pmw Package > > from Pmw import * > > Martin David Vaughan Email: David.Vaughan@gifford.uk.com From stewart at midtoad.homelinux.org Tue Sep 28 23:11:32 2004 From: stewart at midtoad.homelinux.org (stewart@midtoad.homelinux.org) Date: Tue Sep 28 23:07:48 2004 Subject: [Tkinter-discuss] Tip: how to enable/disable menu items In-Reply-To: References: Message-ID: <1096405892.4159d38421e8b@midtoad.homelinux.org> I need to be able to enable or disable menus in a Tkinter app that uses a Pmw menubar. I easily found a sample app (first sample below) that shows how to disable a Tkinter menubar, but I'm using the Pmw widget set, so this sample won't work as listed. So I went looking for clues, and it took quite a while to find them! Eventually I found something, and with some experimentation, got it to work. My sample app is attached (second sample below). The trick is to reference menu entries by an index number (0 for the first entry, 1 for the second, etc.). You can also enable or disable cascading menus this way (though I haven't tried disabling individual entries in a cascaded menu). The non-obvious part is that if you want to disable, say, the 'Options' menu, you have to enter 'Options-menu' in the following line: self.menuBar.component('Options-menu').entryconfig(0,state='disabled') Hope this helps someone! cheers Stewart #--- sample 1: Disabling Tkinter menu items -------- from Tkinter import * root=Tk() def hello(): print "hello !" def toggle(): if submenu.entrycget(0,"state")=="normal": submenu.entryconfig(0,state=DISABLED) submenu.entryconfig(1,label="Speak please") else: submenu.entryconfig(0,state=NORMAL) submenu.entryconfig(1,label="Quiet please") menubar = Menu(root) submenu=Menu(menubar,tearoff=0) submenu2=Menu(submenu,tearoff=0) submenu2.add_command(label="Hello", command=hello) # this cascade will have index 0 in submenu submenu.add_cascade(label="Say",menu=submenu2,state=DISABLED) # these commands will have index 1 and 2 submenu.add_command(label="Speak please",command=toggle) submenu.add_command(label="Exit", command=root.quit) menubar.add_cascade(label="Test",menu=submenu) # display the menu root.config(menu=menubar) root.mainloop() # -------- Sample Two: Disabling Pmw menuBar items ------------ title = 'Disable menuBar items demonstration' # Import Pmw from this directory tree. import sys sys.path[:0] = ['../../..'] import Tkinter import tkFont import tkMessageBox import Pmw class Demo: def __init__(self, parent): 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') 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') menuBar.addmenuitem('Options', 'command', 'Enable/disable the menu', command = self.toggle, font=self.font, label = 'Disable Size menu') # 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 toggle(self): '''disable the first Options menu item, or enable it if already disabled. item 0 is the first menu item, item 1 is the second, etc. Note that to disable an item in the Options menu, you have to enter "Options-menu" below. Similarly, for an item in File menu, enter File-menu''' if self.menuBar.component('Options-menu').entrycget(0,"state")=="normal": self.menuBar.component('Options-menu').entryconfig(0,state='disabled') self.menuBar.component('Options-menu').entryconfig(2,label="Enable Size menu") else: self.menuBar.component('Options-menu').entryconfig(0,state='normal') self.menuBar.component('Options-menu').entryconfig(2,label="Disable Size menu") 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')} self.font = newFont[size] print 'new font size: ', size, ' ', str(self.font) 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() From mfranklin1 at gatwick.westerngeco.slb.com Thu Sep 30 12:54:29 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu Sep 30 12:54:35 2004 Subject: [Tkinter-discuss] strange bind problem... Message-ID: Hi All, Hope you can help I have written a quick HangMan game for my 6 year old son - not me ;-) And it works great..... but when the word changes, after guessing all the right letters, I get an extra 'guess' at the start of the next word. I guess you would have to run it to see what I mean... Sorry it's a bit long from Tkinter import * from string import letters, lowercase import random import time import os import sys FONT = "Courier 36 bold" class HangMan(Tk): def __init__(self): Tk.__init__(self) self.title("HangMan") self.bind("", self.binder) self.words = ["oyster", "toy", "destroy", "employ", "convoy", "royal", "cowboy", "enjoy", "annoy", "voyage"] random.shuffle(self.words) f = Frame(self) self.canvas = Canvas(f, background = "white", width = 300, height=300) self.canvas.pack(side = "left") self.drawman() self.letters = {} lf = Frame(f) col = 0 row = 0 for letter in lowercase: l = Label(lf, text=letter, font=FONT) l.grid(row=row, column=col) self.letters[letter] = l col = col + 1 if col == 6: row = row + 1 col = 0 lf.pack(side = "left") f.pack() f = Frame(self) self.theword = Label(f, text="_ _ _ _ _", font=FONT) self.theword.pack(side="left") f.pack(fill="x") self.setword() def setword(self): self.guessed = [] self.currentword = self.words.pop() self.theword.config(text="_ " * len(self.currentword)) for l in self.letters.values(): l.config(fg = "black") def binder(self, event): key = event.keysym print "binder called", event.keycode, key if key not in letters: ## ignore return "break" if key not in self.guessed: self.guessed.append(key) self.strike(key) self.showletter() if key not in self.currentword: self.shownext() return "break" return "break" def shownext(self): ## draw the next part of the hang man try: id = self.bodyparts.pop() except: ## try this word again! self.showword() time.sleep(4) self.drawman() self.words.append(self.currentword) self.setword() return "break" try: self.canvas.itemconfig(id, outline="black") except: self.canvas.itemconfig(id, fill="black") def showword(self): self.theword.config(text=self.currentword) self.update() def showletter(self): #~ print "showletter called" out = [] for c in self.currentword: if c in self.guessed: out.append(c) else: out.append("_") self.theword.config(text=" ".join(out)) self.update() if "_" in out: # keep going.... pass else: time.sleep(4) self.drawman() self.setword() def strike(self, letter): l = self.letters[letter] l.config(fg = "red") def drawman(self): self.canvas.delete("all") self.bodyparts = [] id = self.canvas.create_line(50, 250, 250, 250, fill="white") self.bodyparts.append(id) id = self.canvas.create_line(50, 250, 50, 50, fill="white") self.bodyparts.append(id) id = self.canvas.create_line(50, 50, 150, 50, fill="white") self.bodyparts.append(id) id = self.canvas.create_line(150, 50, 150, 75, fill="white") self.bodyparts.append(id) # head id = self.canvas.create_oval(140, 75, 160, 95, outline="white") self.bodyparts.append(id) id = self.canvas.create_line(150, 95, 150, 150, fill="white") self.bodyparts.append(id) # leg id = self.canvas.create_line(150, 150, 125, 175, fill="white") self.bodyparts.append(id) # leg id = self.canvas.create_line(150, 150, 175, 175, fill="white") self.bodyparts.append(id) # arm id = self.canvas.create_line(150, 95, 125, 115, fill="white") self.bodyparts.append(id) # arm id = self.canvas.create_line(150, 95, 175, 115, fill="white") self.bodyparts.append(id) self.bodyparts.reverse() hm = HangMan() hm.mainloop() Hope you can help, Martin. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From mfranklin1 at gatwick.westerngeco.slb.com Thu Sep 30 13:47:12 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu Sep 30 13:47:19 2004 Subject: [Tkinter-discuss] Re: strange bind problem... References: Message-ID: In reply to myself! On Thu, 30 Sep 2004 11:54:29 +0100, Martin Franklin wrote: > > Hi All, > > > > Hope you can help I have written a quick HangMan game for my 6 > year old son - not me ;-) > > And it works great..... but when the word changes, after guessing > all the right letters, I get an extra 'guess' at the start of the next > word. I guess you would have to run it to see what I mean... > > Sorry it's a bit long > > > from Tkinter import * > from string import letters, lowercase > import random > import time > import os > import sys > > > > FONT = "Courier 36 bold" > > > class HangMan(Tk): > def __init__(self): > Tk.__init__(self) > self.title("HangMan") > self.bind("", self.binder) > > self.words = ["oyster", "toy", "destroy", "employ", "convoy", > "royal", "cowboy", "enjoy", "annoy", "voyage"] > random.shuffle(self.words) > > f = Frame(self) > > self.canvas = Canvas(f, background = "white", width = 300, > height=300) > self.canvas.pack(side = "left") > > self.drawman() > > self.letters = {} > lf = Frame(f) > col = 0 > row = 0 > for letter in lowercase: > l = Label(lf, text=letter, font=FONT) > l.grid(row=row, column=col) > self.letters[letter] = l > col = col + 1 > if col == 6: > row = row + 1 > col = 0 > lf.pack(side = "left") > f.pack() > > f = Frame(self) > self.theword = Label(f, text="_ _ _ _ _", font=FONT) > self.theword.pack(side="left") > f.pack(fill="x") > self.setword() > > def setword(self): > self.guessed = [] > self.currentword = self.words.pop() > self.theword.config(text="_ " * len(self.currentword)) > > for l in self.letters.values(): > l.config(fg = "black") > > > > > def binder(self, event): > key = event.keysym > print "binder called", event.keycode, key > if key not in letters: > ## ignore > return "break" > > if key not in self.guessed: > self.guessed.append(key) > self.strike(key) > self.showletter() > if self.showletter()=='complete': return 'break' # or just return? Here is the problem... self.showletter() should return 'complete' if the word is complete so this function does not continue > if key not in self.currentword: > self.shownext() > return "break" > return "break" > > def shownext(self): > ## draw the next part of the hang man > > try: > id = self.bodyparts.pop() > except: > ## try this word again! > self.showword() > time.sleep(4) > > self.drawman() > self.words.append(self.currentword) > self.setword() > return "break" > try: > self.canvas.itemconfig(id, outline="black") > except: > self.canvas.itemconfig(id, fill="black") > > > def showword(self): > self.theword.config(text=self.currentword) > self.update() > > > > def showletter(self): > #~ print "showletter called" > out = [] > for c in self.currentword: > if c in self.guessed: > out.append(c) > else: > out.append("_") > > > self.theword.config(text=" ".join(out)) > self.update() > if "_" in out: > # keep going.... > pass > else: > time.sleep(4) > > self.drawman() > self.setword() > return 'complete' Above neds to resurn 'complete' (or somthing) to calling function If anyone is interested in having this code drop me a line... Cheers Martin -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From padmaja at agere.com Thu Sep 30 13:53:13 2004 From: padmaja at agere.com (Jayanthi, Satya Padmaja (Satya Padmaja)) Date: Thu Sep 30 13:53:20 2004 Subject: [Tkinter-discuss] TCL-Tkinter-Python Interface - "Debug Assertion Failed!" Message-ID: Hi : I am facing the following problem in the interaction between Python, Tkinter and TCL. Can anyone please give me some ideas on how to solve it ? I have a hardware, which can be controlled using TCL commands. I am writing a python script which calls the relavant TCL commands and in turn controls the hardware. I am using Tkinter as an interface to the Python and TCL scripts. The python script runs very well, without any problem. But, at the end of the run, a window pops up with an error message. The message is as follows: "Debug Assertion Failed !!! Program : F\Python23\python.exe File : dbgheap.c Line : 1044 Expression : _CrtIsValidHeapPointer(pUserData)..." My Python script looks something like this : import Tkinter root = Tkinter.Tk() root.tk.eval('source tcl_file.tcl') userName = 'abc' root.tk.eval('Init_hardware %s' %(userName)) My TCL functions : proc Init_hardware {userName} { load "hardware_name.dll" hardware_name_pkg # This line actually initializes the hardware hardware_name init -user userName } Any ideas will be highly appreciated. Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20040930/98ef237c/attachment.htm From jepler at unpythonic.net Thu Sep 30 16:04:14 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Thu Sep 30 16:04:23 2004 Subject: [Tkinter-discuss] TCL-Tkinter-Python Interface - "Debug Assertion Failed!" In-Reply-To: References: Message-ID: <20040930140413.GD7559@unpythonic.net> This is not necessarily a Tk bug. This message is a low-level message from the Windows C runtime. You can find nearly 400 references to this message by searching google http://www.google.com/search?q=_CrtIsValidHeapPointer+dbgheap.c http://groups.google.com/groups?q=_CrtIsValidHeapPointer+dbgheap.c Most of the messages are unrelated to Python or Tk. Some of the messages imply it's a DLL or MSVC++ version mismatch. Others imply it's an application or library bug (such as a double free or use-after-free bug). It's possible that this bug is in your "hardware_name.dll". The bug probably shows up at shutdown because at this time lots of memory is freed, and if the memory is a double-free type error this is a very likely time for it to appear. If you can recreate this problem without using an extra dll, or with a simple DLL that is "clearly correct", we'd be interested in hearing more. If not, there's little we can do, because it strongly implies that the bug is in "hardware_name.dll". Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040930/30986975/attachment.pgp