From python at bdurham.com Wed Dec 1 18:15:36 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 12:15:36 -0500 Subject: [Tkinter-discuss] Anyone building MS Office-like ribbonbar interfaces using Tkinter? Message-ID: <1291223736.21698.1408107393@webmail.messagingengine.com> Curious if any of you are building MS Office-like ribbonbar user interfaces using Tkinter? If so, I would love to see a screenshot to see what is possible. We're starting to get more requests for this type of modern user interface. Personally, I hate the new MS Office ribbonbars (after more than 2 years of trying to like this interface), but I have to admit they do look visually more appealing (or at least more modern) than traditional menu/toolbars interfaces. What are your thoughts regarding the ribbonbar widget - useful, annoying, important, impossible to implement in Tkinter, etc? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From oc-spam66 at laposte.net Wed Dec 1 17:49:08 2010 From: oc-spam66 at laposte.net (oc-spam66) Date: Wed, 01 Dec 2010 17:49:08 +0100 Subject: [Tkinter-discuss] event_generate with user_data field Message-ID: <4CF67C84.1090104@laposte.net> Hello, I feel the need to send data along with an event_generate(). If I understand correctly, this is not yet possible with Tkinter. However, I see that a patch was proposed in 2008: http://bugs.python.org/issue3405 "Add support for the new data option supported by event generate (Tk 8.5)" What is the status of this patch? Is there a problem with it? Will it be accepted? O.C. From prog at vtr.net Wed Dec 1 19:26:02 2010 From: prog at vtr.net (craf) Date: Wed, 01 Dec 2010 15:26:02 -0300 Subject: [Tkinter-discuss] Decorate un Frame with window managers title bar, etc en Tkinter 8.5 Message-ID: <1291227962.2202.1.camel@cristian-desktop> Hi. I use python 3.1 and Tkinter 8.5 in Ubuntu 9.10 I would like to turn a frame into a toolbox, ,and for that I read that you can use the command wm manage (window) The information can be found at: http://www.tcl.tk/man/tcl8.5/TkCmd/wm.htm#M39 the explanation says: wm manage widget: The widget specified will become a stand alone top-level window. The window will be decorated with the window managers title bar, etc. Only frame, labelframe and toplevel widgets can be used with this command. Attempting to pass any other widget type will raise an error. Attempting to manage a toplevel widget is benign and achieves nothing. See also GEOMETRY MANAGEMENT. I have tried to use it in Tkinter but I can not know how is its structure. In Tkinter should be: ---TEST CODE------------------- from Tkinter import master = Tk() frame = Frame(master) wm_manager(Frame) master.mainloop() -------------------------------- But this does not work. I appreciate any of this item Regards. Cristian Abarz?a From klappnase at web.de Wed Dec 1 20:36:40 2010 From: klappnase at web.de (Michael Lange) Date: Wed, 1 Dec 2010 20:36:40 +0100 Subject: [Tkinter-discuss] Decorate un Frame with window managers title bar, etc en Tkinter 8.5 In-Reply-To: <1291227962.2202.1.camel@cristian-desktop> References: <1291227962.2202.1.camel@cristian-desktop> Message-ID: <20101201203640.fa29ea9f.klappnase@web.de> Hi, Thus spoketh craf unto us on Wed, 01 Dec 2010 15:26:02 -0300: (...) > > In Tkinter should be: > > ---TEST CODE------------------- > > from Tkinter import > > master = Tk() > frame = Frame(master) > wm_manager(Frame) I think it should rather be frame.wm_manage() . It seems like this hasn't made it into Tkinter yet (at least this is true for 2.6.5) . Thus you will have to use Tkinter's Tcl interface, like this: >>> from Tkinter import * >>> root = Tk() >>> f = Frame(root, bg='white') >>> f.pack(fill='both', expand=1) >>> f.wm_manage() Traceback (most recent call last): File "", line 1, in AttributeError: Frame instance has no attribute 'wm_manage' >>> f.tk.call('wm', 'manage', f._w) '' >>> This worked fine here. I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. I'm a soldier, not a diplomat. I can only tell the truth. -- Kirk, "Errand of Mercy", stardate 3198.9 From kw at codebykevin.com Wed Dec 1 23:21:05 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 01 Dec 2010 17:21:05 -0500 Subject: [Tkinter-discuss] Anyone building MS Office-like ribbonbar interfaces using Tkinter? In-Reply-To: <1291223736.21698.1408107393@webmail.messagingengine.com> References: <1291223736.21698.1408107393@webmail.messagingengine.com> Message-ID: <4CF6CA51.2080606@codebykevin.com> On 12/1/10 12:15 PM, python at bdurham.com wrote: > Curious if any of you are building MS Office-like ribbonbar user > interfaces using Tkinter? If so, I would love to see a screenshot to see > what is possible. > > We're starting to get more requests for this type of modern user > interface. Personally, I hate the new MS Office ribbonbars (after more > than 2 years of trying to like this interface), but I have to admit they > do look visually more appealing (or at least more modern) than > traditional menu/toolbars interfaces. > > What are your thoughts regarding the ribbonbar widget - useful, > annoying, important, impossible to implement in Tkinter, etc? > Malcolm Tkribbon might be of interest: http://bit.ly/hLrwIO That link includes the announcement and a download link. And a few screenshots: http://www.ellogon.org/~petasis/tcl/TkRibbon/images/TkRibbon-Default.png http://www.ellogon.org/~petasis/tcl/TkRibbon/images/TkRibbon-Minimised.png http://www.ellogon.org/~petasis/tcl/TkRibbon/images/TkRibbon-Floating.png This is a Tcl/Tk package, so you'll have to write some wrapper code to access it from Tkinter. The library is listed as alpha-level code, but its author, Georgios Petasis, is one of the foremost Tcl/Tk deveopers out there--he's also written the TDND library (supports native drag-and-drop) and TkGecko, which wraps a Firefox window inside Tk--so it's safe to say the library is of high quality. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From python at bdurham.com Thu Dec 2 02:17:20 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 20:17:20 -0500 Subject: [Tkinter-discuss] Right justify Label against Entry using pack? Message-ID: <1291252640.1751.1408199169@webmail.messagingengine.com> I'm experimenting with geometry layouts and would like to know if its possible to line up a Label and an Entry widget (in the same horizontal line) and have the Label widget right align to the Entry widget. I know I can do this via grid, but I'm wondering if this is possible via pack. Here's the 1 line layout I'm trying to achieve: [Label] [Entry ] ^^^ Where the ^^^ indicates leading space due to right alignment of the label against its Entry. Listed below is my test code. I've tried using Tkinter's Label and ttk's Label. I've tried using anchor, justify, and fill in various combinations without success. One interesting observation: the ttk Label widget always seems to align left in the scenario below while I can get the Tkinter Label widget to center or left align, but never right align. Perhaps I'm confused about when to use justification vs. alignment to achieve my goal? Your thoughts appreciated! import Tkinter as tk import ttk root = tk.Tk() frame = tk.Frame( root ) parent = frame label = tk.Label( parent ) # note that I'm explictly setting width to create an environment for alignment or justification label.config( text='Password', width=20, justify='right' ) label.pack( side='left', anchor='e', padx=4, pady=4 ) entry = ttk.Entry( parent ) entry.pack( side='left', anchor='w', fill='x', expand=True, padx=4, pady=4 ) frame.pack( side='top', anchor='n', fill='x', expand=True, padx=4, pady=4 ) root.mainloop() Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmcmonagle at velseis.com Thu Dec 2 03:23:40 2010 From: jmcmonagle at velseis.com (John McMonagle) Date: Thu, 2 Dec 2010 12:23:40 +1000 Subject: [Tkinter-discuss] Right justify Label against Entry using pack? In-Reply-To: <1291252640.1751.1408199169@webmail.messagingengine.com> References: <1291252640.1751.1408199169@webmail.messagingengine.com> Message-ID: <20101202021723.M64477@velseis.com.au> > I'm experimenting with geometry layouts and would like to know if > its possible to line up a Label and an Entry widget (in the same > horizontal line) and have the Label widget right align to the > Entry widget Yes, it is possible. > > Here's the 1 line layout I'm trying to achieve: > > [Label] [Entry ] > ^^^ > Where the ^^^ indicates leading space due to right alignment of > the label against its Entry. > The justify argument in Label is used to apply the appropriate alignment of the text within the label if that text should span multiple lines. The following simplification of your code works for me on linux, also illustrating the use of justify: rom Tkinter import * r = Tk() f = Frame(r) l = Label(r, text="Password\nHurry up, I'm waiting", width=20, anchor=E, justify=RIGHT) l.pack(side=LEFT, fill=X, anchor=E, expand=NO, padx=2) e = Entry(r) e.pack(side=LEFT, anchor=W, fill=X, expand=YES) f.pack(fill=X, expand=YES) r.mainloop() From python at bdurham.com Thu Dec 2 04:10:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 22:10:44 -0500 Subject: [Tkinter-discuss] Right justify Label against Entry using pack? In-Reply-To: <20101202021723.M64477@velseis.com.au> References: <1291252640.1751.1408199169@webmail.messagingengine.com> <20101202021723.M64477@velseis.com.au> Message-ID: <1291259444.30788.1408212857@webmail.messagingengine.com> John, > The following simplification of your code works for me on linux, also illustrating the use of justify: Thank you for your explanation and sample code. My problem was I didn't know that anchor was an option for widgets - I thought this option only applied to the pack() method. Configuring my widgets with an anchor='w' gives me the solution I'm looking for. Malcolm From python at bdurham.com Thu Dec 2 05:12:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 23:12:37 -0500 Subject: [Tkinter-discuss] Anyone building MS Office-like ribbonbar interfaces using Tkinter? In-Reply-To: <4CF6CA51.2080606@codebykevin.com> References: <1291223736.21698.1408107393@webmail.messagingengine.com> <4CF6CA51.2080606@codebykevin.com> Message-ID: <1291263157.13069.1408219731@webmail.messagingengine.com> Kevin, > Tkribbon might be of interest: > > http://bit.ly/hLrwIO > > That link includes the announcement and a download link. > > And a few screenshots: > > http://www.ellogon.org/~petasis/tcl/TkRibbon/images/TkRibbon-Default.png > http://www.ellogon.org/~petasis/tcl/TkRibbon/images/TkRibbon-Minimised.png > http://www.ellogon.org/~petasis/tcl/TkRibbon/images/TkRibbon-Floating.png WOW! :) Thank you!! Malcolm From python at bdurham.com Thu Dec 2 05:31:00 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 01 Dec 2010 23:31:00 -0500 Subject: [Tkinter-discuss] Removing/disabling a resizable window's maximize button under Windows Message-ID: <1291264260.17500.1408219959@webmail.messagingengine.com> Looking for advice on how to remove or disable a *resizable* window's maximize button under Windows. I'm using Python 2.7 for Windows. Background: I have a resizable window with min and max sizes set via the window's minsize() and maxsize() methods. When a user clicks the maximize button, the window moves to the upper left of the display. This is very confusing to my users so I would like to prevent that behavior. My research shows several ways to disable a maximize button - but none of these techniques seem to apply to resizable windows? 1. Prevent a window from resizing via the resizable( False, False ) method. 2. Remove all the window's controls (and border) via the overrideredirect( True ) method. 3. Use the mysterious transient(1) method (this raises an exception under Windows). Is there a way I can trap the maximize event (what event to bind to?) and return "break" to prevent the maximize from happening (or better yet, substitute my own behavior instead)? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Thu Dec 2 07:04:16 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 02 Dec 2010 01:04:16 -0500 Subject: [Tkinter-discuss] Customize horizontal padding between image and text in Label widget? Message-ID: <1291269856.6712.1408230215@webmail.messagingengine.com> Is there a way to customize the horizontal padding between an image and text in a Label widget when compound=left or right? The 2 ways I can think of are: 1. Use PIL to dynamically add columns of pixels to an image 2. Insert or append spaces to the text= option of the label to force the separation of image and text What I'm looking for is a way to specify the horizontal padding (between image and text) in pixels. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Dec 2 11:21:19 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 2 Dec 2010 11:21:19 +0100 Subject: [Tkinter-discuss] Removing/disabling a resizable window's maximize button under Windows In-Reply-To: <1291264260.17500.1408219959@webmail.messagingengine.com> References: <1291264260.17500.1408219959@webmail.messagingengine.com> Message-ID: <20101202112119.f4db39b0.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Wed, 01 Dec 2010 23:31:00 -0500: (...) > > Is there a way I can trap the maximize event (what event to bind > to?) and return "break" to prevent the maximize from happening > (or better yet, substitute my own behavior instead)? The only thing I can think of is to catch the event and try to determine the current state of the window, like: def on_configure(event): if event.widget.wm_state() == 'zoomed': ...update the window geometry as desired... root.bind('`, on_configure) The "zoomed" state seems to be valid only for windows and OSX, not X11, so I cannot test this here on my linux box. Alternatively, as a last resort, you might try to remove the title bar with overrideredirect and create your own title bar; the maximize button then should toggle between wm_state('zoomed') and wm_state('normal') on the window. I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Either one of us, by himself, is expendable. Both of us are not. -- Kirk, "The Devil in the Dark", stardate 3196.1 From python at bdurham.com Thu Dec 2 12:01:01 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 02 Dec 2010 06:01:01 -0500 Subject: [Tkinter-discuss] Removing/disabling a resizable window's maximize button under Windows In-Reply-To: <20101202112119.f4db39b0.klappnase@web.de> References: <1291264260.17500.1408219959@webmail.messagingengine.com> <20101202112119.f4db39b0.klappnase@web.de> Message-ID: <1291287661.11821.1408260943@webmail.messagingengine.com> Hi Michael, The only thing I can think of is to catch the event and try to determine the current state of the window, like: def on_configure(event): if event.widget.wm_state() == 'zoomed': ...update the window geometry as desired... root.bind('`, on_configure) Thanks for your help. Here's what I discovered (Python 2.7 under Windows 7): Binding a toplevel window's event traps events for all of the window's widgets, not just the window itself. So here's how I coded my event handler: def onFrmResize( event=None ): if not hasattr( event.widget, 'state' ): return if event.widget.state() == 'zoomed': # proves I'm trapping maximize event print 'maximize detected' # return 'break' <--- does not work # event.widget.geometry( '+100+100' ) <--- does not work I can confirm that my event handler is being called properly via the print message, but both return 'break' and explicitly setting position via the geometry method appear to be ignored when executed within the event handler. Any other ideas? Thanks, Malcolm From python at bdurham.com Thu Dec 2 12:24:20 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 02 Dec 2010 06:24:20 -0500 Subject: [Tkinter-discuss] Removing/disabling a resizable window's maximize button under Windows In-Reply-To: <1291287661.11821.1408260943@webmail.messagingengine.com> References: <1291264260.17500.1408219959@webmail.messagingengine.com><20101202112119.f4db39b0.klappnase@web.de> <1291287661.11821.1408260943@webmail.messagingengine.com> Message-ID: <1291289060.18257.1408264619@webmail.messagingengine.com> Michael, Here's an updated version of my event handler that restores a window to its previous size/position when a maximize event is detected. Apparently all one can do within the event is change the state of a window - changes to a window's geometry (size/position) are ignored. The following is not a perfect technique - users can still see their window move to the upper left corner of the display and then return to its original state. def onFrmResize( event=None ): if not hasattr( event.widget, 'state' ): return if event.widget.state() == 'zoomed': event.widget.state( 'normal' ) I wonder if there's an event that comes *before* when a window is maximized? Malcolm From klappnase at web.de Thu Dec 2 12:27:26 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 2 Dec 2010 12:27:26 +0100 Subject: [Tkinter-discuss] Removing/disabling a resizable window's maximize button under Windows In-Reply-To: <1291287661.11821.1408260943@webmail.messagingengine.com> References: <1291264260.17500.1408219959@webmail.messagingengine.com> <20101202112119.f4db39b0.klappnase@web.de> <1291287661.11821.1408260943@webmail.messagingengine.com> Message-ID: <20101202122726.2e18085c.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Thu, 02 Dec 2010 06:01:01 -0500: (...) > > Binding a toplevel window's event traps events > for all of the window's widgets, not just the window itself. So here's > how I coded my event handler: > > def onFrmResize( event=None ): > if not hasattr( event.widget, 'state' ): > return > > if event.widget.state() == 'zoomed': > # proves I'm trapping maximize event > print 'maximize detected' > > # return 'break' <--- does not work > # event.widget.geometry( '+100+100' ) <--- does not work > > I can confirm that my event handler is being called properly via the > print message, but both return 'break' and explicitly setting position > via the geometry method appear to be ignored when executed within the > event handler. > return "break" will not work, because the Configure event is triggered *after* the maximizing occurs, I suppose. I can confirm that maximing a window always moves it into the upper left corner of the screen on X11 with IceWM, too. Maybe it's oddities like this which drive some programmers to draw their own custom titlebars instead of using the WM's default ones. > Any other ideas? Actually the first thought was to change the default behavior of the maximize button somehow through wm_protocol(). The obvious wm_protocol("WM_MAXIMIZE_WINDOW") does not work (at least here) though, and it's hard to find documentation on this. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. We do not colonize. We conquer. We rule. There is no other way for us. -- Rojan, "By Any Other Name", stardate 4657.5 From python at bdurham.com Thu Dec 2 19:52:54 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 02 Dec 2010 13:52:54 -0500 Subject: [Tkinter-discuss] Control vertical position of checkbutton [x] when wrap= creates multiline checkbutton captions Message-ID: <1291315974.18068.1408340929@webmail.messagingengine.com> Is it possible to control the vertical position of the checkbutton widget's [x] when the checkbutton has multi-line text? It appears that Tkinter vertically centers the [x] relative to the word-wrapped checkbutton text that spans multiple lines (activated via the wrap= option). I would like to anchor the [x] component of the checkbutton widget to the top of the widget, eg. aligned with the first line of the checkbutton's caption. Is this possible? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From prog at vtr.net Fri Dec 3 18:04:27 2010 From: prog at vtr.net (craf) Date: Fri, 03 Dec 2010 14:04:27 -0300 Subject: [Tkinter-discuss] Using a window style in a Toplevel window Message-ID: <1291395867.4604.13.camel@cristian-desktop> Hi. I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. CODE:---------------------------------------------------- module:FMain.py from tkinter import ttk from FSecondWindow import * class App: def __init__(self,master): button1 = ttk.Button(master,text='Show TopLevel',command=lambda:window()) button1.pack() master = Tk() app = App(master) style = ttk.Style() style.theme_use('clam') master.mainloop() module:FSecondWindow.py from tkinter import * from tkinter import ttk def window(): t = Toplevel() button2 = Button(t,text='Hello').pack() CODE EXPLANATION:------------------------------------------- 1. From the main module FMain.py call the window function that is located in FSecondWindow module and create a toplevel window. 2.I apply a theme called 'clam' to the master window to improve the appearance of their widgets. QUERY:-------------------------------------------------- How I can make the toplevel window also take the theme 'clam'? Thanks in advance. Regards. Cristian Abarz?a. From prog at vtr.net Fri Dec 3 18:19:29 2010 From: prog at vtr.net (craf) Date: Fri, 03 Dec 2010 14:19:29 -0300 Subject: [Tkinter-discuss] Using a window style in a Toplevel window Message-ID: <1291396769.4604.14.camel@cristian-desktop> Hi. I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10. CODE:---------------------------------------------------- module:FMain.py from tkinter import ttk from FSecondWindow import * class App: def __init__(self,master): button1 = ttk.Button(master,text='Show TopLevel',command=lambda:window()) button1.pack() master = Tk() app = App(master) style = ttk.Style() style.theme_use('clam') master.mainloop() module:FSecondWindow.py from tkinter import * from tkinter import ttk def window(): t = Toplevel() button2 = Button(t,text='Hello').pack() CODE EXPLANATION:------------------------------------------- 1. From the main module FMain.py call the window function that is located in FSecondWindow module and create a toplevel window. 2.I apply a theme called 'clam' to the master window to improve the appearance of their widgets. QUERY:-------------------------------------------------- How I can make the toplevel window also take the theme 'clam'? Thanks in advance. Regards. Cristian Abarz?a. From klappnase at web.de Fri Dec 3 18:21:24 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 3 Dec 2010 18:21:24 +0100 Subject: [Tkinter-discuss] Using a window style in a Toplevel window In-Reply-To: <1291395867.4604.13.camel@cristian-desktop> References: <1291395867.4604.13.camel@cristian-desktop> Message-ID: <20101203182124.d5e10afa.klappnase@web.de> Hi, Thus spoketh craf unto us on Fri, 03 Dec 2010 14:04:27 -0300: (...) > def window(): > t = Toplevel() > button2 = Button(t,text='Hello').pack() > > > CODE EXPLANATION:------------------------------------------- > > 1. From the main module FMain.py call the window function that is > located in FSecondWindow module and create a toplevel window. > > 2.I apply a theme called 'clam' to the master window to improve the > appearance of their widgets. > > QUERY:-------------------------------------------------- > > How I can make the toplevel window also take the theme 'clam'? It should already do this, but you should use ttk widgets instead of the plain tkinter ones (in your example a ttk.Button instead of the Button). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. There's another way to survive. Mutual trust -- and help. -- Kirk, "Day of the Dove", stardate unknown From prog at vtr.net Fri Dec 3 18:42:45 2010 From: prog at vtr.net (craf) Date: Fri, 03 Dec 2010 14:42:45 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Using a window style in a Toplevel window] Message-ID: <1291398165.4604.19.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael Lange > Para: tkinter-discuss at python.org > Asunto: Re: [Tkinter-discuss] Using a window style in a Toplevel > window > Fecha: Fri, 3 Dec 2010 18:21:24 +0100 > > Hi, > > Thus spoketh craf > unto us on Fri, 03 Dec 2010 14:04:27 -0300: > > (...) > > def window(): > > t = Toplevel() > > button2 = Button(t,text='Hello').pack() > > > > > > CODE EXPLANATION:------------------------------------------- > > > > 1. From the main module FMain.py call the window function that is > > located in FSecondWindow module and create a toplevel window. > > > > 2.I apply a theme called 'clam' to the master window to improve the > > appearance of their widgets. > > > > QUERY:-------------------------------------------------- > > > > How I can make the toplevel window also take the theme 'clam'? > > It should already do this, but you should use ttk widgets instead of the > plain tkinter ones (in your example a ttk.Button instead of the Button). > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > There's another way to survive. Mutual trust -- and help. > -- Kirk, "Day of the Dove", stardate unknown > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss OOOPs, my fault.Obvious mistake and did not see. Thank you very much! Regards. Cristian From vinnievega007 at gmail.com Sun Dec 5 23:57:41 2010 From: vinnievega007 at gmail.com (Sean Finnegan) Date: Sun, 5 Dec 2010 17:57:41 -0500 Subject: [Tkinter-discuss] Tkinter Scale Question Message-ID: Hi Everyone, I have successfully visualized 4 layers in Tkinter and am now trying to apply some sort of zoom in/out and pan function so that the layers can be seen more closely. I am using a package to visualize the map layers where i have separate py files for points, polylines, polygons, map, layers, readshapefile, feature, and features, and a main file that tells tkinter what to draw based on the bounding box settings in the map file. I am not exactly sure what path I should be exploring, either a button module or a scale module. I have successfully visualized both, but can not seem to make them take on the functionality that I need. Most recently I am trying some bind code in the main file that I have modified to try and fit the map needs, but it isn't producing the desired functionality either. Can someone please give me some direction as to which way would be best to approach this? from Tkinter import * from Map import * root = Tk() import sys if sys.version_info < (3,): import Tkinter as tk import tkSimpleDialog as tk_dialog else: import tkinter as tk from tkinter import simpledialog as tk_dialog class Viewer(object): #Base class viewer to display map def __init__(self, parent, width=800, height=600, min_x=-2.5, min_y=-1.5, max_x=1.): self.parent = parent self.canvas_width = width self.canvas_height = height # The following are drawing boundaries in the complex plane self.min_x = min_x self.min_y = min_y self.max_x = max_x self.calculate_pixel_size() self.max_y = self.min_y + self.canvas_height*self.pixel_ size self.calculating = False self.nb_iterations = 20 self.normal_zoom(None) self.canvas = tk.Canvas(parent, width=width, height=height) self.canvas.pack() self.status = tk.Label(self.parent, text="", bd=1, relief=tk.SUNKEN, anchor=tk.W) self.status.pack(side=tk.BOTTOM, fill=tk.X) self.status2 = tk.Label(self.parent, text=self.info(), bd=1, relief=tk.SUNKEN, anchor=tk.W) self.status2.pack(side=tk.BOTTOM, fill=tk.X) # We change the size of the image using the keyboard. self.parent.bind("+", self.zoom_in) self.parent.bind("-", self.zoom_out) self.parent.bind("n", self.normal_zoom) self.parent.bind("b", self.bigger_zoom) # Set the maximum number of iterations via a keyboard-triggered event self.parent.bind("i", self.set_max_iter) # We move the canvas using the mouse. self.translation_line = None self.parent.bind("", self.mouse_down) self.parent.bind("", self.mouse_motion) self.parent.bind("", self.mouse_up) self.draw_map() # Needs to be implemented by subclass def info(self): #information about map location''' return "Location: (%f, %f) to (%f, %f)" %(self.min_x, self.min_y, self.max_x, self.max_y) def calculate_pixel_size(self): #Calculates the size of a (square) pixel in complex plane #coordinates based on the canvas_width. self.pixel_size = 1.*(self.max_x - self.min_x)/self.canvas_width return def mouse_down(self, event): #records the x and y positions of the mouse when the left button #is clicked. self.start_x = self.canvas.canvasx(event.x) self.start_y = self.canvas.canvasy(event.y) def mouse_motion(self, event): #keep track of the mouse motion by drawing a line from its #starting point to the current point. x = self.canvas.canvasx(event.x) y = self.canvas.canvasy(event.y) if (self.start_x != event.x) and (self.start_y != event.y) : self.canvas.delete(self.translation_line) self.translation_line = self.canvas.create_line( self.start_x, self.start_y, x, y, fill="orange") self.canvas.update_idletasks() def mouse_up(self, event): #Moves the canvas based on the mouse motion dx = (self.start_x - event.x)*self.pixel_size dy = (self.start_y - event.y)*self.pixel_size self.min_x += dx self.max_x += dx # y-coordinate in complex plane run in opposite direction from # screen coordinates self.min_y -= dy self.max_y -= dy self.canvas.delete(self.translation_line) self.status.config(text="Moving the map. Please wait.") self.status.update_idletasks() self.status2.config(text=self.info()) self.status2.update_idletasks() self.draw_map() def normal_zoom(self, event, scale=1): #Sets the zooming in/out scale to its normal value if scale==1: self.zoom_info = "[normal zoom]" else: self.zoom_info = "[faster zoom]" if event is not None: self.status.config(text=self.zoom_info) self.status.update_idletasks() self.zoom_in_scale = 0.1 self.zoom_out_scale = -0.125 def bigger_zoom(self, event): #Increases the zooming in/out scale from its normal value self.normal_zoom(event, scale=3) self.zoom_in_scale = 0.3 self.zoom_out_scale = -0.4 def zoom_in(self, event): #decreases the size of the region of the complex plane displayed if self.calculating: return self.status.config(text="Zooming in. Please wait.") self.status.update_idletasks() self.change_scale(self.zoom_in_scale) def zoom_out(self, event): #increases the size of the region of the complex plane displayed''' if self.calculating: return self.status.config(text="Zooming out. Please wait.") self.status.update_idletasks() self.change_scale(self.zoom_out_scale) def change_scale(self, scale): #changes the size of the region of the complex plane displayed and #redraws if self.calculating: return dx = (self.max_x - self.min_x)*scale dy = (self.max_y - self.min_y)*scale self.min_x += dx self.max_x -= dx self.min_y += dy self.max_y -= dy self.calculate_pixel_size() self.draw_map() def set_max_iter(self, event): #set maximum number of iterations i = tk_dialog.askinteger('title', 'prompt') if i is not None: self.nb_iterations = i self.status.config(text="Redrawing. Please wait.") self.status.update_idletasks() self.draw_map() def draw_map(self): #draws map on the canvas raise NotImplementedError map = Map(root, 800, 600) map.addLayer('States') map.addLayer('USInterstates') map.addLayer('Rivers') map.addLayer('RoadsRiversIntersect_points') map.vis() root.mainloop() #root.wait_window() Thank you, -Sean -------------- next part -------------- An HTML attachment was scrubbed... URL: From prog at vtr.net Mon Dec 6 16:29:25 2010 From: prog at vtr.net (craf) Date: Mon, 06 Dec 2010 12:29:25 -0300 Subject: [Tkinter-discuss] Create Grips for modificated size controls Message-ID: <1291649365.2684.5.camel@cristian-desktop> Hi. Is it possible to create pinch points(grips) to resize a control, as is done in visual basic.? Example. x-----------x------------x | | | | x Button x ----> Grip | | | | x-----------x------------x Regards. Cristian Abarzua. From klappnase at web.de Mon Dec 6 17:59:45 2010 From: klappnase at web.de (Michael Lange) Date: Mon, 6 Dec 2010 17:59:45 +0100 Subject: [Tkinter-discuss] Create Grips for modificated size controls In-Reply-To: <1291649365.2684.5.camel@cristian-desktop> References: <1291649365.2684.5.camel@cristian-desktop> Message-ID: <20101206175945.561b8372.klappnase@web.de> Hi, Thus spoketh craf unto us on Mon, 06 Dec 2010 12:29:25 -0300: > Hi. > > Is it possible to create pinch points(grips) to resize a control, as is > done in visual basic.? > > Example. > > > > x-----------x------------x > | | > | | > x Button x ----> Grip > | | > | | > x-----------x------------x > this seems not completely trivial, maybe you can set up something using the place geometry manager. Here's a small example that lets you resize a button : ############################################################# from Tkinter import * root = Tk() root.geometry('400x400') f = Frame(root, bd=2, cursor='crosshair') f.place(x=100, y=100) b = Button(f, text='foo', cursor='arrow') b.pack(fill='both', expand=1) def resize(event): # check we're on the button's right edge: if event.x_root > event.widget.winfo_rootx() + 10: w = event.x_root - event.widget.winfo_rootx() f.place(width=w) f.bind('', resize) root.mainloop() ############################################################ This of course only works horizontally and only on the right side of the button, but I think you'll see the point. For methods to resize the button in the three other dimensions, look at the widget's winfo_...() methods, the information provided from pack_info() and the event's attributes. If you want visible grips, you can use a Canvas instead of the Frame and draw for example a few triangles (with create_polygon()) onto the Canvas' edges, and then update the triangles' coordinates from within the resize() callback. You may also want to look at the "Page" Tkinter gui builder (http://page.sourceforge.net/), which (iirc) makes heavy use of place() to resize widgets, and which in fact does exactly what you want (click on a widget -> "grips" are drawn around it , which you can drag), but I think Page is written in Tcl. I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Without followers, evil cannot spread. -- Spock, "And The Children Shall Lead", stardate 5029.5 From prog at vtr.net Mon Dec 6 19:11:26 2010 From: prog at vtr.net (craf) Date: Mon, 06 Dec 2010 15:11:26 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Create Grips for modificated size controls] Message-ID: <1291659086.2076.4.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael Lange > Para: tkinter-discuss at python.org > Asunto: Re: [Tkinter-discuss] Create Grips for modificated size > controls > Fecha: Mon, 6 Dec 2010 17:59:45 +0100 > > Hi, > > Thus spoketh craf > unto us on Mon, 06 Dec 2010 12:29:25 -0300: > > > Hi. > > > > Is it possible to create pinch points(grips) to resize a control, as is > > done in visual basic.? > > > > Example. > > > > > > > > x-----------x------------x > > | | > > | | > > x Button x ----> Grip > > | | > > | | > > x-----------x------------x > > > > this seems not completely trivial, maybe you can set up something using > the place geometry manager. Here's a small example that lets you resize a > button : > > ############################################################# > from Tkinter import * > root = Tk() > root.geometry('400x400') > > f = Frame(root, bd=2, cursor='crosshair') > f.place(x=100, y=100) > b = Button(f, text='foo', cursor='arrow') > b.pack(fill='both', expand=1) > > def resize(event): > # check we're on the button's right edge: > if event.x_root > event.widget.winfo_rootx() + 10: > w = event.x_root - event.widget.winfo_rootx() > f.place(width=w) > > f.bind('', resize) > root.mainloop() > ############################################################ > > This of course only works horizontally and only on the right side of the > button, but I think you'll see the point. For methods to resize the > button in the three other dimensions, look at the widget's winfo_...() > methods, the information provided from pack_info() and the event's > attributes. > If you want visible grips, you can use a Canvas instead of the Frame and > draw for example a few triangles (with create_polygon()) onto the Canvas' > edges, and then update the triangles' coordinates from within the resize() > callback. > > You may also want to look at the "Page" Tkinter gui builder > (http://page.sourceforge.net/), which (iirc) makes heavy use of place() to > resize widgets, and which in fact does exactly what you want (click on a > widget -> "grips" are drawn around it , which you can drag), but I think > Page is written in Tcl. > > I hope this helps > > Michael > > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Without followers, evil cannot spread. > -- Spock, "And The Children Shall Lead", stardate 5029.5 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss Guauuu?, thanks Michael for the code, it's perfect. Regards. CRAF From python at bdurham.com Tue Dec 7 03:38:34 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 06 Dec 2010 21:38:34 -0500 Subject: [Tkinter-discuss] Possible to fade a small Tkinter image into a specific background color? Message-ID: <1291689514.15849.1409009075@webmail.messagingengine.com> Wondering if there's a PIL/Tkinter technique I can use to fade a small image into a specific background color? Use case: I have a small message area that displays both an icon and text message. I can fade my foreground text into its background container by iteratively moving my message text's rgb components towards its background rgb value until my text has the same foreground and background colors. I'm wondering if there's a similar technique I can use with PIL and its Image, ImageTk classes to do the same with an image displayed in Tkinter? I suspect I can do this by inspecting and updating every pixel individually, but this seems very inefficent. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From waynejwerner at gmail.com Tue Dec 7 14:07:30 2010 From: waynejwerner at gmail.com (Wayne Werner) Date: Tue, 7 Dec 2010 07:07:30 -0600 Subject: [Tkinter-discuss] Possible to fade a small Tkinter image into a specific background color? In-Reply-To: <1291689514.15849.1409009075@webmail.messagingengine.com> References: <1291689514.15849.1409009075@webmail.messagingengine.com> Message-ID: On Mon, Dec 6, 2010 at 8:38 PM, wrote: > Wondering if there's a PIL/Tkinter technique I can use to fade a small > image into a specific background color? > > Use case: I have a small message area that displays both an icon and text > message. I can fade my foreground text into its background container by > iteratively moving my message text's rgb components towards its background > rgb value until my text has the same foreground and background colors. > > I'm wondering if there's a similar technique I can use with PIL and its > Image, ImageTk classes to do the same with an image displayed in Tkinter? I > suspect I can do this by inspecting and updating every pixel individually, > but this seems very inefficent. > Well, if you convert the image to a numpy array then you can call some C functions on it so it's not that slow. I'm not sure if any of the other PIL structures are natively C. Any type of fade operation you could call would be doing something on a per-pixel basis (even if the operations themselves are being performed in a very low-level language) anyway. This would just require you to implement it yourself. That's about the extent of my knowledge, there may be others with better ideas (or who can contradict mine!). HTH, Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Dec 7 17:07:43 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 07 Dec 2010 11:07:43 -0500 Subject: [Tkinter-discuss] Force a Frame and/or Text widget to a specific width? Message-ID: <1291738063.3438.1409112281@webmail.messagingengine.com> Is there a technique where I can force a Frame and/or Text widget to a specific width? I understand that width= many times only serves as a hint to Tkinter's layout managers. I'm looking for a width setting technique that's much more forceful than a suggestion :) I'm using a Text widget with wrap='word' as a multi-line label. I pack this Text widget into a Frame. This Text widget wants to grow to a certain width inspite of setting a specific (char) width for Text and a specific (pixel) width for its parent Frame. The only way I can control my Text widget's width is by placing it in a window with a max width set via .maxsize( width, ... ) and resizing disabled via resizable( False, False ). If I skip the resizable( False, False ) statement, then I get the proper sized Text/Frame *until* I go to resize my window ... as soon as I go to resize my window, it snaps to the width it wants to go to when I don't force maxsize(). BTW: I'm using 32-bit Python 2.7 for Windows. Am I missing something obvious? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Dec 7 17:36:02 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 07 Dec 2010 11:36:02 -0500 Subject: [Tkinter-discuss] Force a Frame and/or Text widget to a specific width? In-Reply-To: <1291738063.3438.1409112281@webmail.messagingengine.com> References: <1291738063.3438.1409112281@webmail.messagingengine.com> Message-ID: <1291739762.10941.1409118305@webmail.messagingengine.com> Apologies for the poorly worded description below. I *can* set my Text widget to a specific width. What I would like to do is set my Text widget to a specific width, have it do its layout with word wrap, then remove the width property so that the Text widget can resize as its parent container resizes. Is this possible? Thank you, Malcolm ----- Original message ----- From: python at bdurham.com To: "Python-Tkinter" Date: Tue, 07 Dec 2010 11:07:43 -0500 Subject: [Tkinter-discuss] Force a Frame and/or Text widget to a specific width? Is there a technique where I can force a Frame and/or Text widget to a specific width? I understand that width= many times only serves as a hint to Tkinter's layout managers. I'm looking for a width setting technique that's much more forceful than a suggestion :) I'm using a Text widget with wrap='word' as a multi-line label. I pack this Text widget into a Frame. This Text widget wants to grow to a certain width inspite of setting a specific (char) width for Text and a specific (pixel) width for its parent Frame. The only way I can control my Text widget's width is by placing it in a window with a max width set via .maxsize( width, ... ) and resizing disabled via resizable( False, False ). If I skip the resizable( False, False ) statement, then I get the proper sized Text/Frame *until* I go to resize my window ... as soon as I go to resize my window, it snaps to the width it wants to go to when I don't force maxsize(). BTW: I'm using 32-bit Python 2.7 for Windows. Am I missing something obvious? Thanks, Malcolm _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Dec 7 19:58:17 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 07 Dec 2010 13:58:17 -0500 Subject: [Tkinter-discuss] Recommendations for free and commercial icon/image sets licensed for commercial use? Message-ID: <1291748297.17539.1409144823@webmail.messagingengine.com> Any recommendations for free and commercial icon/image sets licensed for commercial use? I've seen some really high quality icons/images in open source software lately, but I suspect most of these image sets are GPL in nature, thus (in my interpretation) not available for use in commercial products. Thanks, Malcolm From waynejwerner at gmail.com Tue Dec 7 20:38:39 2010 From: waynejwerner at gmail.com (Wayne Werner) Date: Tue, 7 Dec 2010 13:38:39 -0600 Subject: [Tkinter-discuss] Recommendations for free and commercial icon/image sets licensed for commercial use? In-Reply-To: <1291748297.17539.1409144823@webmail.messagingengine.com> References: <1291748297.17539.1409144823@webmail.messagingengine.com> Message-ID: On Tue, Dec 7, 2010 at 12:58 PM, wrote: > Any recommendations for free and commercial icon/image sets > licensed for commercial use? > > I've seen some really high quality icons/images in open source > software lately, but I suspect most of these image sets are GPL > in nature, thus (in my interpretation) not available for use in > commercial products. > Just a suggestion - you may want to search CC licensed works - some of them are share and share alike, but others do allow commercial derivatives. HTH, Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From prog at vtr.net Tue Dec 7 20:44:20 2010 From: prog at vtr.net (craf) Date: Tue, 07 Dec 2010 16:44:20 -0300 Subject: [Tkinter-discuss] Change font and size in control ttk.Entry Message-ID: <1291751060.2801.5.camel@cristian-desktop> Hi. I'm trying to change the font type and size of a ttk.Entry control. Example: from tkinter import * from tkinter import ttk master=Tk() s = ttk.Style() s.theme_use('clam') s.configure('TEntry', font='Monaco') entrada = ttk.Entry(master, style='TEntry') entrada.pack() master.mainloop() Unfortunately does not work. Is there another way to do this? Thank you very much in advance. Regards. Cristian Abarzua. I USE: Python 3.1 - Tkinter 8.5 - Ubuntu 9.10 From prog at vtr.net Tue Dec 7 21:06:24 2010 From: prog at vtr.net (craf) Date: Tue, 07 Dec 2010 17:06:24 -0300 Subject: [Tkinter-discuss] [Fwd: Change font and size in control ttk.Entry] Message-ID: <1291752384.2801.7.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: craf > Para: Python Tkinter Ingles > Asunto: [Tkinter-discuss] Change font and size in control ttk.Entry > Fecha: Tue, 07 Dec 2010 16:44:20 -0300 > > Hi. > > I'm trying to change the font type and size of a ttk.Entry control. > > Example: > > from tkinter import * > from tkinter import ttk > > > master=Tk() > s = ttk.Style() > s.theme_use('clam') > s.configure('TEntry', font='Monaco') > > entrada = ttk.Entry(master, style='TEntry') > entrada.pack() > > master.mainloop() > > Unfortunately does not work. > Is there another way to do this? > > Thank you very much in advance. > > Regards. > > Cristian Abarzua. > > I USE: Python 3.1 - Tkinter 8.5 - Ubuntu 9.10 > Hi. I leave the answer for which you have the same problem: from tkinter import * from tkinter import ttk master=Tk() s = ttk.Style() s.theme_use('clam') entrada = ttk.Entry(master,font='TkDefaultFont 12' ) entrada.pack() master.mainloop() Regards. CRAF From python at bdurham.com Tue Dec 7 23:12:05 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 07 Dec 2010 17:12:05 -0500 Subject: [Tkinter-discuss] Possible to create single pixel wide horizontal/vertical ttk.Separator's? Message-ID: <1291759925.5150.1409175591@webmail.messagingengine.com> Is there a way to create single pixel wide horizontal and vertical ttk.Separator()'s? Python 2.7/Windows: When I magnify the ttk Separators they are built as 2 parallel lines - one line gray and one line a light/white color. The latter color added to create a subtle 3d effect? I would like to create single pixel wide separators that have the system default gray color. A bonus would be the ability to programmatically discover the system color used for a separator's gray band. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Tue Dec 7 23:28:34 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 07 Dec 2010 17:28:34 -0500 Subject: [Tkinter-discuss] Recommendations for free and commercial icon/image sets licensed for commercial use? In-Reply-To: <1291748297.17539.1409144823@webmail.messagingengine.com> References: <1291748297.17539.1409144823@webmail.messagingengine.com> Message-ID: <4CFEB512.4010509@codebykevin.com> On 12/7/10 1:58 PM, python at bdurham.com wrote: > Any recommendations for free and commercial icon/image sets > licensed for commercial use? > > I've seen some really high quality icons/images in open source > software lately, but I suspect most of these image sets are GPL > in nature, thus (in my interpretation) not available for use in > commercial products. > > Thanks, > Malcolm > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > KDE's Oxygen icons, which I use in my apps, are LGPL: http://www.codebykevin.com/COPYING.txt --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From edward at unicornschool.org Thu Dec 9 07:22:26 2010 From: edward at unicornschool.org (Edward Cannon) Date: Wed, 8 Dec 2010 22:22:26 -0800 Subject: [Tkinter-discuss] [Image-SIG] Possible to fade a small Tkinter image into a specific background color? In-Reply-To: References: <1291689514.15849.1409009075@webmail.messagingengine.com> Message-ID: using the blend function with a solid color image (bg color) and your image will work, a simple loop changing the alpha value is all you need. In my experience this is pretty fast. Check the documentation for details. Edward Cannon Unicorn School On Tue, Dec 7, 2010 at 5:07 AM, Wayne Werner wrote: > > On Mon, Dec 6, 2010 at 8:38 PM, wrote: >> >> Wondering if there's a PIL/Tkinter technique I can use to fade a small image into a specific background color? >> >> Use case: I have a small message area that displays both an icon and text message. I can fade my foreground text into its background container by iteratively moving my message text's rgb components towards its background rgb value until my text has the same foreground and background colors. >> >> I'm wondering if there's a similar technique I can use with PIL and its Image, ImageTk classes to do the same with an image displayed in Tkinter? I suspect I can do this by inspecting and updating every pixel individually, but this seems very inefficent. > > Well, if you convert the image to a numpy array then you can call some C functions on it so it's not that slow. I'm not sure if any of the other PIL structures are natively C. Any type of fade operation you could call would be doing something on a per-pixel basis (even if the operations themselves are being performed in a very low-level language) anyway. This would just require you to implement it yourself. > That's about the extent of my knowledge, there may be others with better ideas (or who can contradict mine!). > HTH, > Wayne > > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From python at bdurham.com Thu Dec 9 14:46:26 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 08:46:26 -0500 Subject: [Tkinter-discuss] Possible to set the min/max height or width of a Tkinter or ttk Frame? Message-ID: <1291902386.12139.1409483065@webmail.messagingengine.com> The size of Tkinter windows can be controlled via the following methods: .minsize() .maxsize() .resizable() Are there equivalent ways to control the size of Tkinter or ttk Frames? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Thu Dec 9 15:25:33 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 09:25:33 -0500 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? Message-ID: <1291904733.22086.1409489543@webmail.messagingengine.com> Is there a pack equivalent of the grid_remove() method where a widget's original pack() settings are restored on a re-pack()? Use case: When I show a packed widget that has been hidden via pack_forget(), I would like to have the widget re-packed with its original pack settings when I issue the widget.pack() show request. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Thu Dec 9 15:37:33 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 09 Dec 2010 09:37:33 -0500 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? In-Reply-To: <1291904733.22086.1409489543@webmail.messagingengine.com> References: <1291904733.22086.1409489543@webmail.messagingengine.com> Message-ID: <4D00E9AD.50505@codebykevin.com> On 12/9/10 9:25 AM, python at bdurham.com wrote: > Is there a pack equivalent of the grid_remove() method where a widget's > original pack() settings are restored on a re-pack()? > > Use case: When I show a packed widget that has been hidden via > pack_forget(), I would like to have the widget re-packed with its > original pack settings when I issue the widget.pack() show request. > > Thanks, > Malcolm No, there isn't. You have to be careful with the packing order for pack_forget() to work--this works best if you limit its use to the last widget group packed. Otherwise, it may be packed in a different location, with surprising results. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From python at bdurham.com Thu Dec 9 15:46:11 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 09:46:11 -0500 Subject: [Tkinter-discuss] How to determine if a widget is pack()-ed or unpacked via pack_forget()? Message-ID: <1291905971.27047.1409493145@webmail.messagingengine.com> Is there a widget method that returns whether a widget is pack()-ed or unpacked? The same question applies to widget's placed with the grid() or place() layout managers. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Thu Dec 9 15:48:54 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 09:48:54 -0500 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? In-Reply-To: <4D00E9AD.50505@codebykevin.com> References: <1291904733.22086.1409489543@webmail.messagingengine.com> <4D00E9AD.50505@codebykevin.com> Message-ID: <1291906134.27483.1409493353@webmail.messagingengine.com> Kevin, > No, there isn't. You have to be careful with the packing order for pack_forget() to work--this works best if you limit its use to the last widget group packed. Otherwise, it may be packed in a different location, with surprising results. Thanks for that tip! (You're right - I would have been surprised!) Is there a best practice way to show/hide specific widgets (or containers) in Tkinter? Is grid a better layout manager than pack for this type of use case? Malcolm From klappnase at web.de Thu Dec 9 15:51:23 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 9 Dec 2010 15:51:23 +0100 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? In-Reply-To: <1291904733.22086.1409489543@webmail.messagingengine.com> References: <1291904733.22086.1409489543@webmail.messagingengine.com> Message-ID: <20101209155123.40658819.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Thu, 09 Dec 2010 09:25:33 -0500: > Is there a pack equivalent of the grid_remove() method where a > widget's original pack() settings are restored on a re-pack()? > Use case: When I show a packed widget that has been hidden via > pack_forget(), I would like to have the widget re-packed with its > original pack settings when I issue the widget.pack() show > request. There's nothing like that built in, but it is quite easy to set it up: from Tkinter import * root = Tk() root.geometry('200x200') class pFrame(Frame): def __init(self, *args, **kw): Frame.__init__(self, *args, **kw) self._packinfo = {} def pack(self, *args, **kw): Frame.pack(self, *args, **kw) self._packinfo = self.pack_info() pack_configure = pack def pack_recall(self): self.pack(**self._packinfo) f = pFrame(root, bg='yellow') f.pack(fill='both', expand=1) f.pack_forget() f.pack_recall() root.mainloop() I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. We're all sorry for the other guy when he loses his job to a machine. But when it comes to your job -- that's different. And it always will be different. -- McCoy, "The Ultimate Computer", stardate 4729.4 From python at bdurham.com Thu Dec 9 15:57:53 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 09:57:53 -0500 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? In-Reply-To: <1291906134.27483.1409493353@webmail.messagingengine.com> References: <1291904733.22086.1409489543@webmail.messagingengine.com><4D00E9AD.50505@codebykevin.com> <1291906134.27483.1409493353@webmail.messagingengine.com> Message-ID: <1291906673.29722.1409493927@webmail.messagingengine.com> > Is there a best practice way to show/hide specific widgets (or containers) in Tkinter? Another way to control visibility might be to size a control/widget a height/width of 0,0. But Tkinter ignores this type of size request. (It does accept a size request of 1,1, but in the case of Frame, immediately resizes itself to its 'natural' size). Anyone have any thoughts on this approach? Malcolm From klappnase at web.de Thu Dec 9 16:26:16 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 9 Dec 2010 16:26:16 +0100 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? In-Reply-To: <1291906134.27483.1409493353@webmail.messagingengine.com> References: <1291904733.22086.1409489543@webmail.messagingengine.com> <4D00E9AD.50505@codebykevin.com> <1291906134.27483.1409493353@webmail.messagingengine.com> Message-ID: <20101209162616.728be3bd.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Thu, 09 Dec 2010 09:48:54 -0500: > Kevin, > > > No, there isn't. You have to be careful with the packing order for > pack_forget() to work--this works best if you limit its use to the last > widget group packed. Otherwise, it may be packed in a different > location, with surprising results. > > Thanks for that tip! (You're right - I would have been surprised!) > > Is there a best practice way to show/hide specific widgets (or > containers) in Tkinter? > > Is grid a better layout manager than pack for this type of use case? > Definitely yes, as Kevin pointed out, my convenience class will fail, too, if there are e.g. multiple frames packed in the same container with side='left' . Using grid() will save you a lot of headaches which will compensate the more complex setup of grid() compared to pack(). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. It would be illogical to kill without reason. -- Spock, "Journey to Babel", stardate 3842.4 From python at bdurham.com Thu Dec 9 16:45:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 10:45:48 -0500 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? In-Reply-To: <20101209162616.728be3bd.klappnase@web.de> References: <1291904733.22086.1409489543@webmail.messagingengine.com><4D00E9AD.50505@codebykevin.com><1291906134.27483.1409493353@webmail.messagingengine.com> <20101209162616.728be3bd.klappnase@web.de> Message-ID: <1291909548.10380.1409504009@webmail.messagingengine.com> Michael, Thanks for the pack_forget() implementation and for the confirmation that one should use grid vs. pack for scenarios that require showing/hiding widgets. Malcolm From python at bdurham.com Thu Dec 9 16:52:39 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 09 Dec 2010 10:52:39 -0500 Subject: [Tkinter-discuss] Recommendations on when to use pack vs. grid layouts? Message-ID: <1291909959.12396.1409504869@webmail.messagingengine.com> Are there any best practice tips regarding when one should use pack vs. grid for their layouts? >From what I've been reading via google, the concencus seems to be that grid can handle any pack scenario but not vice-versa. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Dec 9 17:33:29 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 9 Dec 2010 17:33:29 +0100 Subject: [Tkinter-discuss] Recommendations on when to use pack vs. grid layouts? In-Reply-To: <1291909959.12396.1409504869@webmail.messagingengine.com> References: <1291909959.12396.1409504869@webmail.messagingengine.com> Message-ID: <20101209173329.c9fa4264.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Thu, 09 Dec 2010 10:52:39 -0500: > Are there any best practice tips regarding when one should use > pack vs. grid for their layouts? > > >From what I've been reading via google, the concencus seems to be > that grid can handle any pack scenario but not vice-versa. > At least it's hard to figure out something that pack can do and grid can't. Imho it's better to use grid, if you cannot setup your layout with pack without using extra frames. To tell the truth, I hardly ever use pack at all, as far as I can see, the only advantage of pack is that it takes 2 or 3 extra lines of code when you want to replace pack (fill='both', expand=1) with grid. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "Life and death are seldom logical." "But attaining a desired goal always is." -- McCoy and Spock, "The Galileo Seven", stardate 2821.7 From waynejwerner at gmail.com Thu Dec 9 18:13:27 2010 From: waynejwerner at gmail.com (Wayne Werner) Date: Thu, 9 Dec 2010 11:13:27 -0600 Subject: [Tkinter-discuss] Recommendations on when to use pack vs. grid layouts? In-Reply-To: <20101209173329.c9fa4264.klappnase@web.de> References: <1291909959.12396.1409504869@webmail.messagingengine.com> <20101209173329.c9fa4264.klappnase@web.de> Message-ID: On Thu, Dec 9, 2010 at 10:33 AM, Michael Lange wrote: > Thus spoketh python at bdurham.com > unto us on Thu, 09 Dec 2010 10:52:39 -0500: > > > Are there any best practice tips regarding when one should use > > pack vs. grid for their layouts? > > > > >From what I've been reading via google, the concencus seems to be > > that grid can handle any pack scenario but not vice-versa. > > > > At least it's hard to figure out something that pack can do and grid > can't. > Imho it's better to use grid, if you cannot setup your layout with > pack without using extra frames. To tell the truth, I hardly ever use > pack at all, as far as I can see, the only advantage of pack is that it > takes 2 or 3 extra lines of code when you want to replace pack > (fill='both', expand=1) with grid. I agree. I pretty much only use pack if I'm throwing something together really quick and simple. If you have more than 3 or 4 widgets, it's probably better to use grid, especially if you want some specific layout options. HTH, Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Thu Dec 9 18:18:10 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Thu, 9 Dec 2010 18:18:10 +0100 Subject: [Tkinter-discuss] How to determine if a widget is pack()-ed or unpacked via pack_forget()? In-Reply-To: <1291905971.27047.1409493145@webmail.messagingengine.com> References: <1291905971.27047.1409493145@webmail.messagingengine.com> Message-ID: Look at: w.winfo_ismapped() ...Note that if a widget IS packed, but the parent (or some ancestor) is not, this will return False. w.winfo_manager() -- will return "" if the widget is not packed/gridded etc., disregarding whether the parent is not packed. Otherwise returns info on how it is placed. Mick On Thu, Dec 9, 2010 at 3:46 PM, wrote: > Is there a widget method that returns whether a widget is pack()-ed or > unpacked? > > The same question applies to widget's placed with the grid() or place() > layout managers. > > Thank you, > Malcolm > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From michael.odonnell at uam.es Thu Dec 9 18:21:29 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Thu, 9 Dec 2010 18:21:29 +0100 Subject: [Tkinter-discuss] Recommendations on when to use pack vs. grid layouts? In-Reply-To: <1291909959.12396.1409504869@webmail.messagingengine.com> References: <1291909959.12396.1409504869@webmail.messagingengine.com> Message-ID: If you are placing a row of widgets into a frame, with pack you don't have to keep track of which column you are up to, just pack them one after the other. Mick On Thu, Dec 9, 2010 at 4:52 PM, wrote: > Are there any best practice tips regarding when one should use pack vs. grid > for their layouts? > > From what I've been reading via google, the concencus seems to be that grid > can handle any pack scenario but not vice-versa. > > Thanks, > Malcolm > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From prog at vtr.net Thu Dec 9 19:52:43 2010 From: prog at vtr.net (craf) Date: Thu, 09 Dec 2010 15:52:43 -0300 Subject: [Tkinter-discuss] methods of control PanedWindow Message-ID: <1291920763.4308.6.camel@cristian-desktop> I Do learn to work with methods of control PanedWindow.The only that I failed to understand how they are used are: PanedWindow.proxy_coord() PanedWindow.proxy_forget() PanedWindow.proxy_place(x, y) Does anyone know what they are good? Annex code test: -------------------------------------------------------------- from tkinter import * master = Tk() master.geometry('220x160') def proxycoord(event): x = event.x y= event.y print(paned.proxy_coord()) paned = PanedWindow(master, orient = HORIZONTAL, background = 'grey',showhandle = TRUE) paned.pack(fill = BOTH, expand = YES) Entry1 = Entry(paned) Entry2 = Entry(paned) Entry3 = Entry(paned) paned.add(Entry1) paned.add(Entry2) paned.add(Entry3) paned.bind('',proxycoord) master.mainloop() --------------------------------------------------------------- Thanks in advance. Regards. Cristian Abarzua F From Chris.Barker at noaa.gov Thu Dec 9 18:58:09 2010 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Thu, 09 Dec 2010 09:58:09 -0800 Subject: [Tkinter-discuss] [Image-SIG] Possible to fade a small Tkinter image into a specific background color? In-Reply-To: References: <1291689514.15849.1409009075@webmail.messagingengine.com> Message-ID: <4D0118B1.4060501@noaa.gov> On 12/7/10 5:07 AM, Wayne Werner wrote: > On Mon, Dec 6, 2010 at 8:38 PM, Wondering if there's a PIL/Tkinter technique I can use to fade a > small image into a specific background color? > Well, if you convert the image to a numpy array then you can call some C > functions on it so it's not that slow. Once you've got it in a numpy array, you can use numpy to manipulate it -- you're unlikely to need C. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From klappnase at web.de Thu Dec 9 20:38:41 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 9 Dec 2010 20:38:41 +0100 Subject: [Tkinter-discuss] methods of control PanedWindow In-Reply-To: <1291920763.4308.6.camel@cristian-desktop> References: <1291920763.4308.6.camel@cristian-desktop> Message-ID: <20101209203841.9adacdb9.klappnase@web.de> Thus spoketh craf unto us on Thu, 09 Dec 2010 15:52:43 -0300: > I Do learn to work with methods of control PanedWindow.The only that I > failed to understand how they are used are: > > PanedWindow.proxy_coord() > PanedWindow.proxy_forget() > PanedWindow.proxy_place(x, y) > > > Does anyone know what they are good? Probably to move the sash: ###################################### from Tkinter import * root = Tk() pw = PanedWindow(root) pw.pack(fill='both', expand=1) l1 = Listbox(pw) l2 = Listbox(pw) a = pw.add(l1) b = pw.add(l2) def on_left(ev): x,y = pw.proxy_coord() pw.proxy_place(x-1, y) def on_right(ev): x,y = pw.proxy_coord() pw.proxy_place(x+1, y) def on_return(ev): pw.sash_place(0, *pw.proxy_coord()) pw.proxy_forget() pw.update_idletasks() pw.proxy_place(*pw.sash_coord(0)) pw.proxy_forget() root.bind('', on_left) root.bind('', on_right) root.bind('', on_return) root.mainloop() ##################################### However I don't know why one would want to do this, either. I'd prefer to directly move the sash (as with opaqueresize=True). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. The more complex the mind, the greater the need for the simplicity of play. -- Kirk, "Shore Leave", stardate 3025.8 From prog at vtr.net Thu Dec 9 21:01:20 2010 From: prog at vtr.net (craf) Date: Thu, 09 Dec 2010 17:01:20 -0300 Subject: [Tkinter-discuss] [Fwd: Re: methods of control PanedWindow] Message-ID: <1291924880.4308.8.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael Lange > Para: tkinter-discuss at python.org > Asunto: Re: [Tkinter-discuss] methods of control PanedWindow > Fecha: Thu, 9 Dec 2010 20:38:41 +0100 > > Thus spoketh craf > unto us on Thu, 09 Dec 2010 15:52:43 -0300: > > > I Do learn to work with methods of control PanedWindow.The only that I > > failed to understand how they are used are: > > > > PanedWindow.proxy_coord() > > PanedWindow.proxy_forget() > > PanedWindow.proxy_place(x, y) > > > > > > Does anyone know what they are good? > > Probably to move the sash: > > ###################################### > from Tkinter import * > root = Tk() > pw = PanedWindow(root) > pw.pack(fill='both', expand=1) > l1 = Listbox(pw) > l2 = Listbox(pw) > a = pw.add(l1) > b = pw.add(l2) > > def on_left(ev): > x,y = pw.proxy_coord() > pw.proxy_place(x-1, y) > def on_right(ev): > x,y = pw.proxy_coord() > pw.proxy_place(x+1, y) > def on_return(ev): > pw.sash_place(0, *pw.proxy_coord()) > pw.proxy_forget() > > pw.update_idletasks() > pw.proxy_place(*pw.sash_coord(0)) > pw.proxy_forget() > > root.bind('', on_left) > root.bind('', on_right) > root.bind('', on_return) > root.mainloop() > ##################################### > > However I don't know why one would want to do this, either. I'd prefer to > directly move the sash (as with opaqueresize=True). > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > The more complex the mind, the greater the need for the simplicity of > play. > -- Kirk, "Shore Leave", stardate 3025.8 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss Hi Michael. Thank you very much for giving me a light I really did not know that these methods were used. Regards Cristian Abarzua From msa01 at bitflipper.ca Thu Dec 9 19:24:23 2010 From: msa01 at bitflipper.ca (Cam Farnell) Date: Thu, 09 Dec 2010 14:24:23 -0400 Subject: [Tkinter-discuss] Recommendations on when to use pack vs. grid layouts? In-Reply-To: <1291909959.12396.1409504869@webmail.messagingengine.com> References: <1291909959.12396.1409504869@webmail.messagingengine.com> Message-ID: <4D011ED7.5080809@bitflipper.ca> Another option is to use Rapyd-TK (http://www.bitflipper.ca/rapyd/). It only uses pack but it makes it trivially easy to add additional frames and it also makes it really easy to rearrange the layout of your widgets, something not easy with pack or grid by themselves. Cheers Cam Farnell python at bdurham.com wrote: > Are there any best practice tips regarding when one should use pack vs. > grid for their layouts? > > From what I've been reading via google, the concencus seems to be that > grid can handle any pack scenario but not vice-versa. > > Thanks, > Malcolm From sridharr at activestate.com Fri Dec 10 06:04:18 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 9 Dec 2010 21:04:18 -0800 Subject: [Tkinter-discuss] how make active python 3 use active tcl on mac os? In-Reply-To: References: Message-ID: <98B04515-421D-4A0C-9E12-77DB2DD8D0CD@activestate.com> On 2010-11-23, at 1:14 PM, David Cortesi wrote: > I installed ActiveState Python 3.1.4, and also ActiveState Tcl/Tk, both on Mac OS X 10.6. > > Python3 executing "import * from tkinter" is getting and executing the Apple version of Tcl/Tk which is level 8.5.7. It appears to be getting it from /System/Library/Frameworks/Tk.framework and Tcl.framework. > > The ActiveTc (level 8.5.9) is in /Library/Frameworks rather than /System/Library Frameworks. It contains a bug fix that I need. > > Any suggestions on how I tell python3 to find the later Tcl/Tk instead of the Apple one? David, We just released ActiveTcl 8.5 64-bit and the corresponding ActivePython 2.7 & 3.1 builds that now use ActiveTcl instead of Apple's Tcl/Tk on Snow Leopard. http://www.activestate.com/activetcl/downloads http://www.activestate.com/activepython/downloads -srid From python at bdurham.com Fri Dec 10 15:23:35 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 10 Dec 2010 09:23:35 -0500 Subject: [Tkinter-discuss] pack equivalent of grid_remove(), eg. pack_remove() ? In-Reply-To: <20101209155123.40658819.klappnase@web.de> References: <1291904733.22086.1409489543@webmail.messagingengine.com> <20101209155123.40658819.klappnase@web.de> Message-ID: <1291991015.4114.1409675511@webmail.messagingengine.com> Michael, Your pack_forget() code works like a charm! Thank you, Malcolm From: "Michael Lange" To: tkinter-discuss at python.org Date: Thu, 9 Dec 2010 15:51:23 +0100 There's nothing like that built in, but it is quite easy to set it up: from Tkinter import * root = Tk() root.geometry('200x200') class pFrame(Frame): def __init(self, *args, **kw): Frame.__init__(self, *args, **kw) self._packinfo = {} def pack(self, *args, **kw): Frame.pack(self, *args, **kw) self._packinfo = self.pack_info() pack_configure = pack def pack_recall(self): self.pack(**self._packinfo) f = pFrame(root, bg='yellow') f.pack(fill='both', expand=1) f.pack_forget() f.pack_recall() root.mainloop() From python at bdurham.com Fri Dec 10 15:43:03 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 10 Dec 2010 09:43:03 -0500 Subject: [Tkinter-discuss] How to determine if a widget is pack()-ed or unpacked via pack_forget()? In-Reply-To: References: <1291905971.27047.1409493145@webmail.messagingengine.com> Message-ID: <1291992183.9973.1409678873@webmail.messagingengine.com> Mick, Perfect - that's just what I was looking for. Malcolm From: "Michael O'Donnell" Look at: w.winfo_ismapped() ...Note that if a widget IS packed, but the parent (or some ancestor) is not, this will return False. w.winfo_manager() -- will return "" if the widget is not packed/gridded etc., disregarding whether the parent is not packed. Otherwise returns info on how it is placed. From python at bdurham.com Fri Dec 10 15:44:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 10 Dec 2010 09:44:48 -0500 Subject: [Tkinter-discuss] Recommendations on when to use pack vs. grid layouts? In-Reply-To: References: <1291909959.12396.1409504869@webmail.messagingengine.com> Message-ID: <1291992288.10616.1409679337@webmail.messagingengine.com> Mick, > If you are placing a row of widgets into a frame, with pack you don't have to keep track of which column you are up to, just pack them one after the other. I think grid() will automatically increment the row if you don't specify it. Malcolm From python at bdurham.com Fri Dec 10 16:13:28 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 10 Dec 2010 10:13:28 -0500 Subject: [Tkinter-discuss] How do Tkinter's Entry/Text support for Ctrl+X/Ctrl+C/Ctrl+V (cut, copy, paste) work in non-English locales? Message-ID: <1291994008.19872.1409683151@webmail.messagingengine.com> It seems that Tkinter Entry and Text widgets have built in support for basic clipboard functionality via the keystrokes Ctrl+X/Ctrl+C/Ctrl+V (cut, copy, paste). Of course these make sense for English speaking locales. How does this functionality work when Tkinter is used in non-English locales? Are these keystroke shortcuts hard coded or do they switch to locale/language specific shortcuts? Is there a way to turnoff this functionality or map these built-in clipboard keystrokes to different keys? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Fri Dec 10 16:23:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 10 Dec 2010 10:23:37 -0500 Subject: [Tkinter-discuss] Tips for using Tkinter in non-US locales and/or locale module integration with Tkinter Entry widgets Message-ID: <1291994617.23049.1409684313@webmail.messagingengine.com> I noticed there are a lot of non-US developers on this list. I'm looking for tips on using Tkinter in non-US locales. In particular: 1. Are there any Unicode or font specific issues to be concerned about? 2. Are you using the locale module to control how you display or parse data moving into and out of Entry widgets? (has anyone wrapped the Entry widget with locale aware code?) 3. Are you using gettext with Tkinter and if so, are there any tips or traps to watch for? (I think gettext integration should be seamless, but didn't think it would hurt to confirm this) Thank you (gracias, danke, merci, grazie, muito obrigado, tusen takk, spasibo balshoye, duizend maal dank, ... etc) Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Fri Dec 10 17:12:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 10 Dec 2010 11:12:37 -0500 Subject: [Tkinter-discuss] What determines the initial position of Tkinter's root and Toplevel() windows? Message-ID: <1291997557.6070.1409692947@webmail.messagingengine.com> What determines the initial position of Tkinter's root and Toplevel() windows? Under Windows (running Python 2.7), my root window appears to show up in random positions (usually clustered around the upper left of my display). The position of my first Toplevel() window appears to be random as well. Subsequent Toplevel() windows appear offset from the position of the first Toplevel() window by a consistent(?) amount of space. I think the pattern for subsequent Toplevel() window positions might be described as a "tiled" effect? Are these Tkinter specific behaviors or OS specific behaviors? What approach do you take with your window placement: - accept the default window position as given by Tkinter - proactively specify a window position - center your windows on the desktop - remember and restore window positions (and sizes?) across sessions - other Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Dec 10 18:46:30 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 10 Dec 2010 18:46:30 +0100 Subject: [Tkinter-discuss] How do Tkinter's Entry/Text support for Ctrl+X/Ctrl+C/Ctrl+V (cut, copy, paste) work in non-English locales? In-Reply-To: <1291994008.19872.1409683151@webmail.messagingengine.com> References: <1291994008.19872.1409683151@webmail.messagingengine.com> Message-ID: <20101210184630.a93637a7.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Fri, 10 Dec 2010 10:13:28 -0500: > It seems that Tkinter Entry and Text widgets have built in > support for basic clipboard functionality via the keystrokes > Ctrl+X/Ctrl+C/Ctrl+V (cut, copy, paste). > > Of course these make sense for English speaking locales. How does > this functionality work when Tkinter is used in non-English > locales? Are these keystroke shortcuts hard coded or do they > switch to locale/language specific shortcuts? > These bindings are hard-wired in the tk.tcl file, depending on the platform (X11, windows, mac). > Is there a way to turnoff this functionality or map these > built-in clipboard keystrokes to different keys? This is in fact quite straightforward. For example if you want to change the default binding for a paste event from Ctrl-v into Ctrl-q , you can do: >>> e1=Entry() >>> e1.pack() >>> e1.event_delete('<>', '') >>> e1.event_add('<>', '') I'm not sure if this would make sense, though. Aren't these default bindings the same for any locale (at least this is true for germany :)? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. There are certain things men must do to remain men. -- Kirk, "The Ultimate Computer", stardate 4929.4 From python at bdurham.com Fri Dec 10 18:55:03 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 10 Dec 2010 12:55:03 -0500 Subject: [Tkinter-discuss] How do Tkinter's Entry/Text support for Ctrl+X/Ctrl+C/Ctrl+V (cut, copy, paste) work in non-English locales? In-Reply-To: <20101210184630.a93637a7.klappnase@web.de> References: <1291994008.19872.1409683151@webmail.messagingengine.com> <20101210184630.a93637a7.klappnase@web.de> Message-ID: <1292003703.6305.1409710817@webmail.messagingengine.com> Michael, > >>> e1.event_delete('<>', '') > >>> e1.event_add('<>', '') Thank you! That's the *exact* technique I was searching for. > I'm not sure if this would make sense, though. Aren't these default bindings the same for any locale (at least this is true for germany :)? I mistakenly thought that these bindings were localized for each language. Thanks for correcting me. Malcolm From klappnase at web.de Fri Dec 10 19:35:17 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 10 Dec 2010 19:35:17 +0100 Subject: [Tkinter-discuss] Tips for using Tkinter in non-US locales and/or locale module integration with Tkinter Entry widgets In-Reply-To: <1291994617.23049.1409684313@webmail.messagingengine.com> References: <1291994617.23049.1409684313@webmail.messagingengine.com> Message-ID: <20101210193517.da975c83.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Fri, 10 Dec 2010 10:23:37 -0500: > I noticed there are a lot of non-US developers on this list. I'm > looking for tips on using Tkinter in non-US locales. > > In particular: > > 1. Are there any Unicode or font specific issues to be concerned > about? > > 2. Are you using the locale module to control how you display or > parse data moving into and out of Entry widgets? (has anyone > wrapped the Entry widget with locale aware code?) > > 3. Are you using gettext with Tkinter and if so, are there any > tips or traps to watch for? (I think gettext integration should > be seamless, but didn't think it would hurt to confirm this) I haven't used python3 yet, I think there aren't separate unicode and byte string types anymore (can someone confirm this?) which will make things probably straightforward. In python-2.x using gettext can be quite a pain in the neck. To be on the safe side, I always use gettext with unicode=True and take care that any string that is passed to tk is converted into unicode first and any string that python receives from Tk is converted into a byte string before processing it (the odd thing is that sometimes you don't know in advance if you get a byte string or unicode). When dealing with gettext I always use a module with some convenience methods to make this easier: ################################################## sysencoding = _sysencoding().lower() def fsdecode(input, errors='strict'): '''Fail-safe decodes a string into unicode.''' if not isinstance(input, unicode): try: return unicode(input, sysencoding, errors) except UnicodeError: print 'Unicode Error while decoding string:', input return unicode(input, sysencoding, 'replace') return input def fsencode(input, errors='strict'): '''Fail-safe encodes a unicode string into system default encoding.''' if isinstance(input, unicode): try: return input.encode(sysencoding, errors) except UnicodeError: print 'Unicode Error while encoding string:', input return input.encode(sysencoding, 'replace') return input class UnicodeVar(Tkinter.StringVar): def __init__(self, master=None, errors='strict'): self.errors = errors Tkinter.StringVar.__init__(self, master) def get(self): """Return value of variable as unicode string.""" value = self._tk.globalgetvar(self._name) if isinstance(value, basestring): return fsdecode(value, self.errors) return fsdecode(value, self.errors) def set(self, value): """Set the variable to VALUE.""" return self._tk.globalsetvar(self._name, fsencode(value, self.errors)) ################################################## The tricky thing here is of course the _sysencoding() function that should detect the system default encoding. My function does basically the same as the idlelib.IOBinding module, so you could replace it with def _sysencoding(): import idlelib return idlelib.IOBinding.encoding The fsdecode and fsencode functions proved to be quite handy, in situations where you don't know if you have a byte string or unicode I can simply do for example: message = _('Unsupported file type') + u':\n"%s"' % fsdecode(fname) (if fname is e.g. returned from a tkFileDialog it is unicode in case it contains non-ascii characters, otherwise a byte string; otoh, the same filename returned by os.listdir() is always a byte string!) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "... freedom ... is a worship word..." "It is our worship word too." -- Cloud William and Kirk, "The Omega Glory", stardate unknown From klappnase at web.de Fri Dec 10 19:48:32 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 10 Dec 2010 19:48:32 +0100 Subject: [Tkinter-discuss] What determines the initial position of Tkinter's root and Toplevel() windows? In-Reply-To: <1291997557.6070.1409692947@webmail.messagingengine.com> References: <1291997557.6070.1409692947@webmail.messagingengine.com> Message-ID: <20101210194832.7abbaf2c.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Fri, 10 Dec 2010 11:12:37 -0500: > What determines the initial position of Tkinter's root and > Toplevel() windows? > > Under Windows (running Python 2.7), my root window appears to > show up in random positions (usually clustered around the upper > left of my display). > > The position of my first Toplevel() window appears to be random > as well. Subsequent Toplevel() windows appear offset from the > position of the first Toplevel() window by a consistent(?) amount > of space. I think the pattern for subsequent Toplevel() window > positions might be described as a "tiled" effect? > > Are these Tkinter specific behaviors or OS specific behaviors? If no position is explicitely defined, the window manager will decide where to display a new window. > > What approach do you take with your window placement: > > - accept the default window position as given by Tkinter > - proactively specify a window position > - center your windows on the desktop > - remember and restore window positions (and sizes?) across > sessions > - other Personally I prefer the first (and in some cases the last) option. Forcing my app to appear in the upper left corner or center it on the desktop imho does not make much sense, the users will resize and reposition them as they want anyway. If any explicit geometry specification, then I'd tend to restore the last size and position of the app window, because there is a chance that it comes close to what they actually want. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No problem is insoluble. -- Dr. Janet Wallace, "The Deadly Years", stardate 3479.4 From irvinicus at yahoo.com Sat Dec 11 01:15:27 2010 From: irvinicus at yahoo.com (irvinicus) Date: Fri, 10 Dec 2010 16:15:27 -0800 (PST) Subject: [Tkinter-discuss] Why can't I use the END index with my text widget in Tkinter? Message-ID: <30431052.post@talk.nabble.com> I'm using the text widget to give ongoing updates to the user. When something happens in the program, I want to add an update to the user in the text widget. But I can't figure out how to add each new update onto it's own new line. I've looked through the documentation, but I don't see any methods that would help me, so I figured I could just use the index END and use modifiers on it, but no such luck. Here's my script (my italics, obviously): from Tkinter import * # I import Tkinter into my Python script. ... # Blah blah blah mytextbox.insert(END + 1 lines, textfordisplay) # The interpreter stops and tells me that lines is "invalid syntax". Any suggestions? Thanks for reading? -- View this message in context: http://old.nabble.com/Why-can%27t-I-use-the-END-index-with-my-text-widget-in-Tkinter--tp30431052p30431052.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From klappnase at web.de Sat Dec 11 10:58:03 2010 From: klappnase at web.de (Michael Lange) Date: Sat, 11 Dec 2010 10:58:03 +0100 Subject: [Tkinter-discuss] Why can't I use the END index with my text widget in Tkinter? In-Reply-To: <30431052.post@talk.nabble.com> References: <30431052.post@talk.nabble.com> Message-ID: <20101211105803.b946b09c.klappnase@web.de> Hi, Thus spoketh irvinicus unto us on Fri, 10 Dec 2010 16:15:27 -0800 (PST): > > I'm using the text widget to give ongoing updates to the user. When > something happens in the program, I want to add an update to the user > in the text widget. > > But I can't figure out how to add each new update onto it's own new > line. I've looked through the documentation, but I don't see any > methods that would help me, so I figured I could just use the index END > and use modifiers on it, but no such luck. > > Here's my script (my italics, obviously): > > from Tkinter import * # I import Tkinter into my Python script. > > ... # Blah blah blah > > mytextbox.insert(END + 1 lines, textfordisplay) > # The interpreter stops and tells me that lines is "invalid syntax". Tkinter.END is simply a constant representing the string "end", so you would have to write mytextbox.insert(END + " + 1 lines", textfordisplay) or mytextbox.insert("end + 1 lines", textfordisplay) However at least here (debian linux, tk-8.4), this does not work as expected, when I repeatedly type mytextbox.insert('end + 1 lines', 'foobar') the "foobars" are all appended to the end of the same last line. I guess this because "end" means "end", and this method is only valid for other indices, like "insert" and so on. So if you want to add an empty line to the end of the text widget, the most obvious way is to do: mytextbox.insert(END, os.linesep) or, if you want to save a line, mytextbox.insert(END, os.linesep + textfordisplay) but be careful, this might cause unexpected unicode errors if "textfordisplay" contains any non-ascii characters. For more details on text indices see: http://www.tcl.tk/man/tcl8.4/TkCmd/text.htm#M18 I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Uncontrolled power will turn even saints into savages. And we can all be counted on to live down to our lowest impulses. -- Parmen, "Plato's Stepchildren", stardate 5784.3 From irvinicus at yahoo.com Sat Dec 11 18:28:49 2010 From: irvinicus at yahoo.com (irvinicus) Date: Sat, 11 Dec 2010 09:28:49 -0800 (PST) Subject: [Tkinter-discuss] Why can't I use the END index with my text widget in Tkinter? In-Reply-To: <20101211105803.b946b09c.klappnase@web.de> References: <30431052.post@talk.nabble.com> <20101211105803.b946b09c.klappnase@web.de> Message-ID: <30434402.post@talk.nabble.com> Actually, somebody else sent me mytextbox.insert(END, "\n"+textfordisplay) ...which seems to work fine. Thanks, though. Michael Lange wrote: > > Hi, > > Thus spoketh irvinicus > unto us on Fri, 10 Dec 2010 16:15:27 -0800 (PST): > >> >> I'm using the text widget to give ongoing updates to the user. When >> something happens in the program, I want to add an update to the user >> in the text widget. >> >> But I can't figure out how to add each new update onto it's own new >> line. I've looked through the documentation, but I don't see any >> methods that would help me, so I figured I could just use the index END >> and use modifiers on it, but no such luck. >> >> Here's my script (my italics, obviously): >> >> from Tkinter import * # I import Tkinter into my Python script. >> >> ... # Blah blah blah >> >> mytextbox.insert(END + 1 lines, textfordisplay) >> # The interpreter stops and tells me that lines is "invalid syntax". > > Tkinter.END is simply a constant representing the string "end", so you > would have to write > > mytextbox.insert(END + " + 1 lines", textfordisplay) > or > mytextbox.insert("end + 1 lines", textfordisplay) > > However at least here (debian linux, tk-8.4), this does not work as > expected, when I repeatedly type > > mytextbox.insert('end + 1 lines', 'foobar') > > the "foobars" are all appended to the end of the same last line. I guess > this because "end" means "end", and this method is only valid for other > indices, like "insert" and so on. > > So if you want to add an empty line to the end of the text widget, the > most obvious way is to do: > > mytextbox.insert(END, os.linesep) > > or, if you want to save a line, > > mytextbox.insert(END, os.linesep + textfordisplay) > > but be careful, this might cause unexpected unicode errors if > "textfordisplay" contains any non-ascii characters. > > For more details on text indices see: > > http://www.tcl.tk/man/tcl8.4/TkCmd/text.htm#M18 > > I hope this helps > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Uncontrolled power will turn even saints into savages. And we can all > be counted on to live down to our lowest impulses. > -- Parmen, "Plato's Stepchildren", stardate 5784.3 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- View this message in context: http://old.nabble.com/Why-can%27t-I-use-the-END-index-with-my-text-widget-in-Tkinter--tp30431052p30434402.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From prog at vtr.net Mon Dec 13 00:39:39 2010 From: prog at vtr.net (craf) Date: Sun, 12 Dec 2010 20:39:39 -0300 Subject: [Tkinter-discuss] Ttk.Labelframe control label does not change color Message-ID: <1292197179.6024.8.camel@cristian-desktop> Hi. Changing the background color ttk.Labelframe control, label does not change color. CODE: from tkinter import * from tkinter import ttk master = Tk() master.geometry('200x200') s = ttk.Style() s.configure('TLabelframe', background='blue') labelframe = ttk.Labelframe(master, text='Options', style='TLabelframe') labelframe.pack(fill=BOTH, expand=YES) b = ttk.Button(labelframe, text='Hello World') b.pack() master.mainloop() is a Bug? Regards Cristian. From python at bdurham.com Mon Dec 13 01:46:13 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 12 Dec 2010 19:46:13 -0500 Subject: [Tkinter-discuss] Ttk.Labelframe control label does not change color In-Reply-To: <1292197179.6024.8.camel@cristian-desktop> References: <1292197179.6024.8.camel@cristian-desktop> Message-ID: <1292201173.8525.1409989585@webmail.messagingengine.com> Craf, > Changing the background color ttk.Labelframe control, label does not change color. I believe this is by design, eg. none of the ttk widgets allow their foreground or background colors to be changed because these colors are determined by the system's current color scheme. Malcolm From prog at vtr.net Mon Dec 13 02:15:56 2010 From: prog at vtr.net (craf) Date: Sun, 12 Dec 2010 22:15:56 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Ttk.Labelframe control label does not change color] Message-ID: <1292202956.6024.9.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: python at bdurham.com > Para: craf , Python Tkinter Ingles > > Asunto: Re: [Tkinter-discuss] Ttk.Labelframe control label does not > change color > Fecha: Sun, 12 Dec 2010 19:46:13 -0500 > > Craf, > > > Changing the background color ttk.Labelframe control, label does not change color. > > I believe this is by design, eg. none of the ttk widgets allow their > foreground or background colors to be changed because these colors are > determined by the system's current color scheme. > > Malcolm Hi. I find reason in what you say, but the ideal is that if you change the background color, the label also changed. One solution is to use the option labelwidget but it is not ideal. Regards. Cristian From klappnase at web.de Mon Dec 13 13:45:49 2010 From: klappnase at web.de (Michael Lange) Date: Mon, 13 Dec 2010 13:45:49 +0100 Subject: [Tkinter-discuss] Ttk.Labelframe control label does not change color In-Reply-To: <1292197179.6024.8.camel@cristian-desktop> References: <1292197179.6024.8.camel@cristian-desktop> Message-ID: <20101213134549.24aabe8b.klappnase@web.de> Hi, Thus spoketh craf unto us on Sun, 12 Dec 2010 20:39:39 -0300: > Hi. > > Changing the background color ttk.Labelframe control, label does not > change color. > > CODE: > > from tkinter import * > from tkinter import ttk > > master = Tk() > master.geometry('200x200') > s = ttk.Style() > s.configure('TLabelframe', background='blue') > > labelframe = ttk.Labelframe(master, text='Options', style='TLabelframe') > labelframe.pack(fill=BOTH, expand=YES) > > b = ttk.Button(labelframe, text='Hello World') > b.pack() > master.mainloop() > > is a Bug? No ;) A brief investigation through the default styles delivered with tk revealed the solution (in vistaTheme.tcl, for those whoa are interested :). You need to add one line to your example: s.configure('TLabelframe.Label', background='blue') I haven't used ttk much yet, but I guess this is the usual way for ttk to handle the appearance of "subwidgets". Once you've seen this you can probably get pretty far by trial and error. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. To live is always desirable. -- Eleen the Capellan, "Friday's Child", stardate 3498.9 From prog at vtr.net Mon Dec 13 13:54:59 2010 From: prog at vtr.net (craf) Date: Mon, 13 Dec 2010 09:54:59 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Ttk.Labelframe control label does not change color] Message-ID: <1292244899.4273.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael Lange > Para: tkinter-discuss at python.org > Asunto: Re: [Tkinter-discuss] Ttk.Labelframe control label does not > change color > Fecha: Mon, 13 Dec 2010 13:45:49 +0100 > > Hi, > > Thus spoketh craf > unto us on Sun, 12 Dec 2010 20:39:39 -0300: > > > Hi. > > > > Changing the background color ttk.Labelframe control, label does not > > change color. > > > > CODE: > > > > from tkinter import * > > from tkinter import ttk > > > > master = Tk() > > master.geometry('200x200') > > s = ttk.Style() > > s.configure('TLabelframe', background='blue') > > > > labelframe = ttk.Labelframe(master, text='Options', style='TLabelframe') > > labelframe.pack(fill=BOTH, expand=YES) > > > > b = ttk.Button(labelframe, text='Hello World') > > b.pack() > > master.mainloop() > > > > is a Bug? > > No ;) > A brief investigation through the default styles delivered with tk > revealed the solution (in vistaTheme.tcl, for those whoa are > interested :). You need to add one line to your example: > > s.configure('TLabelframe.Label', background='blue') > > I haven't used ttk much yet, but I guess this is the usual way for ttk to > handle the appearance of "subwidgets". Once you've seen this you can > probably get pretty far by trial and error. > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > To live is always desirable. > -- Eleen the Capellan, "Friday's Child", stardate 3498.9 > _______________________________________________ As always Michael, thank you very much!. Tkinter really is very configurable. Regards. Cristian From prog at vtr.net Mon Dec 13 17:05:07 2010 From: prog at vtr.net (craf) Date: Mon, 13 Dec 2010 13:05:07 -0300 Subject: [Tkinter-discuss] Border color ttk.Entry Message-ID: <1292256307.5054.1.camel@cristian-desktop> Hi. There any way to change the border color of a control ttk.Entry through options or style? Regards. Cristian Ubuntu 9.10 - Tkinter 8.5 From john at nmt.edu Mon Dec 13 21:06:55 2010 From: john at nmt.edu (John W. Shipman) Date: Mon, 13 Dec 2010 13:06:55 -0700 (MST) Subject: [Tkinter-discuss] Tkinter polling example: file copy with progress bar Message-ID: Attached is a Tkinter script that demonstrates polling, that is, performing a long-running process in parallel with the GUI. The script asks for an input file name and an output file name and copies the input file to the output file. The copy operation is done in a child process managed with pexpect, and the GUI reports the progress of the file copy using a Scale widget as a progress bar. Cordially, John W. Shipman, NM Tech Computer Center, Socorro, NM; john at nmt.edu Tkinter 8.4 reference: http://www.nmt.edu/tcc/help/pubs/tkinter/ -------------- next part -------------- #!/usr/bin/env python #================================================================ # copyprogress: File copy with a progress bar for Tkinter 8.4. # - Demonstrates Tkinter .after() and the pexpect module. # Written by John W. Shipman (john at nmt.edu), New Mexico Tech # Computer Center, Socorro, NM 87801 USA. This script is in # the public domain. #---------------------------------------------------------------- # - - - - - I m p o r t s import sys, os, stat import Tkinter as tk import tkFileDialog, tkMessageBox import pexpect # - - - - - M a n i f e s t c o n s t a n t s BUTTON_FONT = ("Helvetica", 17) LABEL_FONT = ("Helvetica", 14) ENTRY_FONT = ("DejaVu Sans Mono", 12) POLL_TIME = 50 # Polling frequency in milliseconds # - - - - - m a i n def main(): """ """ app = App() app.master.title("Copy with progress bar") app.mainloop() # - - - - - c l a s s A p p class App(tk.Frame): '''Copies a file with a progress bar. Widgets: .fromFileVar: StringVar for source file name .fromFileEntry: Entry for source file name .fromFileBrowse: Browse button for source file name .fromFileLabel: Label for above .toFileVar: StringVar for destination file name .toFileEntry: Entry for destination file name .toFileBrowse: Browse button for destination file name .toFileLabel: Label for above .copyButton: Button to start copying .progressVar: DoubleVar for progress scale .progressScale: Scale to show progress Grid plan: 0 1 2 +----------------+-----------------+----------------+ 0 | .fromFileEntry | .fromFileBrowse | .fromFileLabel | +----------------+-----------------+----------------+ 1 | .toFileEntry | .toFileBrowse | .toFileLabel | +----------------+-----------------+----------------+ 2 | .progress | .copyButton | .quitButton | +----------------+-----------------+----------------+ Internal state: .fromFileSize: Source file size in bytes .child: pexpect child process to do the copy ''' # - - - A p p . _ _ i n i t _ _ def __init__(self, master=None): tk.Frame.__init__(self, master) self.grid() self.__createWidgets() # - - - A p p . _ _ c r e a t e w i d g e t s def __createWidgets(self): '''Create all widgets and associated variables. ''' self.fromFileVar = tk.StringVar() self.fromFileEntry = tk.Entry ( self, textvariable=self.fromFileVar, font=ENTRY_FONT, width=50 ) rowx, colx = 0, 0 self.fromFileEntry.grid(row=rowx, column=colx, sticky=tk.E) self.fromFileBrowse = tk.Button ( self, command=self.__browseFrom, font=BUTTON_FONT, text="Browse" ) colx += 1 self.fromFileBrowse.grid(row=rowx, column=colx) self.fromFileLabel = tk.Label ( self, font=LABEL_FONT, text="Source file" ) colx += 1 self.fromFileLabel.grid(row=rowx, column=colx, sticky=tk.W) self.toFileVar = tk.StringVar() self.toFileEntry = tk.Entry ( self, textvariable=self.toFileVar, font=ENTRY_FONT, width=50 ) rowx, colx = rowx+1, 0 self.toFileEntry.grid(row=rowx, column=colx, sticky=tk.E) self.toFileBrowse = tk.Button ( self, command=self.__browseTo, font=BUTTON_FONT, text="Browse" ) colx += 1 self.toFileBrowse.grid(row=rowx, column=colx) self.toFileLabel = tk.Label ( self, font=LABEL_FONT, text="Destination file") colx += 1 self.toFileLabel.grid(row=rowx, column=colx, sticky=tk.W) self.progressVar = tk.DoubleVar() self.progressScale = tk.Scale ( self, length=400, orient=tk.HORIZONTAL, from_=0.0, to=100.0, resolution=0.1, tickinterval=20.0, variable=self.progressVar, label="Percent completion", font=LABEL_FONT ) rowx, colx = rowx+1, 0 self.progressScale.grid(row=rowx, column=colx, sticky=tk.E) self.copyButton = tk.Button ( self, command=self.__copyHandler, font=BUTTON_FONT, text="Copy" ) colx += 1 self.copyButton.grid(row=rowx, column=colx ) self.quitButton = tk.Button ( self, command=self.quit, font=BUTTON_FONT, text="Quit" ) colx += 1 self.quitButton.grid(row=rowx, column=colx, sticky=tk.W) # - - - A p p . _ _ b r o w s e F r o m def __browseFrom(self): '''Handler for Browse button for the source file. ''' # [ if the user enters an existing file name in a popup -> # self.fromFileVar := that name # else -> # f := an empty string ] f = tkFileDialog.askopenfilename(title="Source file name") if len(f) == 0: return else: self.fromFileVar.set(f) # - - - A p p . _ _ b r o w s e T o def __browseTo(self): '''Handler for Browse button for the source file. ''' # [ if the user enters a nonexistent existing file name in # a popup, or enters an existing name and then says it's # okay to overwrite it -> # self.toFileVar := that name # else -> # f := an empty string ] f = tkFileDialog.asksaveasfilename(title="Destination file name") if len(f) == 0: return else: self.toFileVar.set(f) # - - - A p p . _ _ c o p y H a n d l e r def __copyHandler(self): '''Start the file copy process. ''' # [ if the source file name is empty -> # display a popup error message # return # else -> I ] if len(self.fromFileVar.get()) == 0: tkMessageBox.showerror("Error", "Please enter a source file name." ) return # [ if the destination file name is empty -> # show an error popup # return # else if the destination file exists and the user's reply # to a popup indicates they do not want to proceed -> # return # else -> I ] toFileName = self.toFileVar.get() if len(toFileName) == 0: tkMessageBox.showerror("Error", "Please enter a destination file name." ) return elif os.path.exists(toFileName): message = ( "File '%s' exists.\nDo you want to overwrite " "it?" % toFileName ) answer = tkMessageBox.askokcancel("Destination file exists", message, default=tkMessageBox.CANCEL) if not answer: return # [ if the source file exists -> # self.fromFileSize := that file's size in bytes # else -> # display a popup and return ] if not self.__copySetup(): return # [ self.child := a pexpect.spawn child process that copies # the source file to the destination file with -f # self := self with a callback to self.__poll after # POLL_TIME ] self.__startCopy() # - - - A p p . _ _ c o p y S e t u p def __copySetup(self): '''Operations done before the copy is started. [ if the source file exists -> self.fromFileSize := that file's size in bytes return True else -> display an error popup return False ] ''' fromFileName = self.fromFileVar.get() try: self.fromFileSize = self.__measureFile(fromFileName) except OSError, details: tkMessageBox.showerror ( "Source file error", "File %s: %s" % (fromFileName, str(details)) ) return False return True # - - - A p p . _ _ s t a r t C o p y def __startCopy ( self ): '''Start up a file copy operation. [ (self.fromFileVar contains the name of a readable file) and (self.toFileVar contains the name of a writeable file) -> self.child := a pexpect.spawn child process that copies the source file to the destination file with -f self := self with a callback to self.__poll after POLL_TIME ] ''' # [ command := a copy command from the source file to the # destination file, with a force option ] command = ( "cp -f %s %s" % (self.fromFileVar.get(), self.toFileVar.get()) ) # [ self.progressVar := 0 # self := self with a callback after POLL_TIME to # self.__poll ] self.progressVar.set(0.0) self.after(POLL_TIME, self.__poll) # [ self.child := a pexpect.spawn process to run command ] self.child = pexpect.spawn(command) # - - - A p p . _ _ m e a s u r e F i l e def __measureFile(self, fileName): '''Determine the current length of a file, if it exists. [ if fileName can be statted -> return the current length of that file else -> raise OSError ] ''' status = os.stat ( fileName ) return status[stat.ST_SIZE] # - - - A p p . _ _ p o l l def __poll(self): '''Periodic check of the copy progress. [ if self.child has terminated -> self.progressVar := 100.0 self.child := (closed) show a status popup else if we can stat the output file -> self.progressVar := (destination file size / self.fromFileSize) as a percentage self := self with a callback to self.__poll after POLL_TIME ] ''' # [ if self.child has terminated -> # self.progressVar := 100.0 # return # else -> I ] if not self.child.isalive(): self.child.close() self.progressVar.set(100.0) tkMessageBox.showinfo ( "Success", "File %s has been copied to %s, size %s." % (self.fromFileVar.get(), self.toFileVar.get(), self.fromFileSize) ) return # [ if we can stat the output file -> # outFileSize := its size in bytes # else -> # display an error popup # return ] toFileName = self.toFileVar.get() try: toFileSize = self.__measureFile ( toFileName ) except OSError, details: tkMessageBox.showerror ( "Destination file error", "File %s: %s" % (toFileName, str(details)) ) return # [ self.progressVar := toFileSize / self.fromFileSize # as a percentage # self := self with a callback to self.__poll after # POLL_TIME ] self.progressVar.set ( 100.0 * float(toFileSize) / float(self.fromFileSize) ) self.after(POLL_TIME, self.__poll) # - - - - - E p i l o g u e if __name__ == "__main__": main() From klappnase at web.de Tue Dec 14 12:45:13 2010 From: klappnase at web.de (Michael Lange) Date: Tue, 14 Dec 2010 12:45:13 +0100 Subject: [Tkinter-discuss] ssh login through Tkinter - problem on windows Message-ID: <20101214124513.caca58a7.klappnase@web.de> Hi, I am writing a small Tkinter app that collects information about incoming and outgoing phone calls from my router and displays them in a Tkinter gui. The point is that I want to do a passwordless login via ssh to be able to see the list of phone calls without having to log into the router. This works fine on linux, on windows the ssh login works, too, but for some reason it fails as soon as I open the Tkinter gui. A minimal example that exhibits the problem: ######################################### import os, shlex, subprocess, Tkinter root = Tkinter.Tk() cmd = '"C:\Programme\ICW\Bin\ssh.exe" -o ConnectTimeout=10 -l root -i "C:\Dokumente und Einstellungen\klappnase\Eigene Dateien\ssh\id_dsa_BS" 192.168.2.1 /bin/bcm_helper -c 1' #cmd = '"ssh" -o ConnectTimeout=10 -l root -i "/home/klappnase/.ssh/id_dsa_BS" 192.168.2.1 /bin/bcm_helper -c 1' args = shlex.split(cmd) pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False) status = pipe.wait() output = pipe.stdout.read() print output# -> the phone calls list as html snippet root.mainloop() ######################################### As soon as I comment out the Tk window, the output is printed to stdout as expected, but with Tk the login fails. I don't know if this has actually something to do with Tk, though. Any ideas? Thanks in advance Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Violence in reality is quite different from theory. -- Spock, "The Cloud Minders", stardate 5818.4 From python at bdurham.com Tue Dec 14 15:53:14 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 14 Dec 2010 09:53:14 -0500 Subject: [Tkinter-discuss] ssh login through Tkinter - problem on windows In-Reply-To: <20101214124513.caca58a7.klappnase@web.de> References: <20101214124513.caca58a7.klappnase@web.de> Message-ID: <1292338394.16871.1410285099@webmail.messagingengine.com> Michael, > pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False) What happens when you try shell=True? Also, is there a way to run ssh unbuffered? What happens when you exit root.mainloop()? Can you try a root.after( 1000, root.quit ) to see if your example works after Tk exits? Malcolm From klappnase at web.de Tue Dec 14 17:33:15 2010 From: klappnase at web.de (Michael Lange) Date: Tue, 14 Dec 2010 17:33:15 +0100 Subject: [Tkinter-discuss] ssh login through Tkinter - problem on windows In-Reply-To: <1292338394.16871.1410285099@webmail.messagingengine.com> References: <20101214124513.caca58a7.klappnase@web.de> <1292338394.16871.1410285099@webmail.messagingengine.com> Message-ID: <20101214173315.b62cb86d.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Tue, 14 Dec 2010 09:53:14 -0500: > Michael, > > > pipe = subprocess.Popen(args, stdout=subprocess.PIPE, > > stderr=subprocess.STDOUT, shell=False) > > What happens when you try shell=True? > > Also, is there a way to run ssh unbuffered? > > What happens when you exit root.mainloop()? Can you try a root.after( > 1000, root.quit ) to see if your example works after Tk exits? Sure, without Tk it works, the odd thing is that it does not work when Tk is active, in fact I don't even need to call mainloop() to make it fail, a simple root=Tk() is sufficient. I also tried a number of different ways of invoking subprocess.Popen() but nothing helps. I guess that it's probably a problem with the setup of the ssh client rather than actually a Tk bug, but when I asked google, I couldn't find any hints. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Another Armenia, Belgium ... the weak innocents who always seem to be located on a natural invasion route. -- Kirk, "Errand of Mercy", stardate 3198.4 From klappnase at web.de Tue Dec 14 19:38:23 2010 From: klappnase at web.de (Michael Lange) Date: Tue, 14 Dec 2010 19:38:23 +0100 Subject: [Tkinter-discuss] [solved] ssh login through Tkinter - problem on windows In-Reply-To: <20101214173315.b62cb86d.klappnase@web.de> References: <20101214124513.caca58a7.klappnase@web.de> <1292338394.16871.1410285099@webmail.messagingengine.com> <20101214173315.b62cb86d.klappnase@web.de> Message-ID: <20101214193823.69019e02.klappnase@web.de> Thus spoketh Michael Lange unto us on Tue, 14 Dec 2010 17:33:15 +0100: Ok, I can confirm now it was a problem with the ssh install; I tried cygwin's ssh as replacement for Copssh, which then complained "unable to create directory /home/klappnase/.ssh" , obviously because there was no /home/klappnase , so I created this and now it works. I guess that it was the same problem with Copssh, though I can't remember that it gave me such an enlightening error message, but maybe I just missed it. Still it's weird that it worked without Tk, which by the way didn't happen with cygwin's ssh. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Four thousand throats may be cut in one night by a running man. -- Klingon Soldier, "Day of the Dove", stardate unknown From klappnase at web.de Tue Dec 14 19:54:13 2010 From: klappnase at web.de (Michael Lange) Date: Tue, 14 Dec 2010 19:54:13 +0100 Subject: [Tkinter-discuss] Border color ttk.Entry In-Reply-To: <1292256307.5054.1.camel@cristian-desktop> References: <1292256307.5054.1.camel@cristian-desktop> Message-ID: <20101214195413.c2dd18a4.klappnase@web.de> Hi, Thus spoketh craf unto us on Mon, 13 Dec 2010 13:05:07 -0300: > Hi. > > There any way to change the border color of a control ttk.Entry through > options or style? > if you mean the 1- or 2-pixel border used to (typically) draw the "sunken" "3D" effect, then I don't think so. I believe these colors are automagically derived by some internal Tk routine from the background color of the widget. However, you could try some trickery packing the entry into another Frame: root = Tk() f = Frame(root) f.pack(fill='both', expand=1) f1 = Frame(f, bg='blue', relief='sunken', bd=2) f1.pack(padx=100, pady=100) e = Entry(f1, relief='flat', bd=0) e.pack(fill='both', expand=1) root.mainloop() (with ttk widgets you will have to configure the widget's styles instead of adding simple config options of course, but I guess you see the point.) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Our way is peace. -- Septimus, the Son Worshiper, "Bread and Circuses", stardate 4040.7. From python at bdurham.com Wed Dec 15 06:30:12 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 00:30:12 -0500 Subject: [Tkinter-discuss] Ideas for user interface to allow users to change order of ttk.Notebook pages/tabs? Message-ID: <1292391012.4049.1410413553@webmail.messagingengine.com> I'm using the ttk.Notebook widget to manage a list of open files. I create and destroy tabs as a user opens and closes files. I would like to offer my users a way to change the order of the notebook tabs. Ideally I would like my users to be able to drag and drop tabs like they do in Firefox, but I can't see a way to do this with the events exposed by the Notebook widget. Since drag and drop is not available to us, what do you think might be an intuitive user (Tkinter/ttk-based) interface for allowing users to reorder their tabs? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Wed Dec 15 06:54:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 00:54:37 -0500 Subject: [Tkinter-discuss] Change ttk.Notebook tab's font or font height? Message-ID: <1292392477.9462.1410415731@webmail.messagingengine.com> Is there a way to change the ttk.Notebook tab's font or font height? Use case: I would like to use a named font object for my tab captions so a user can change the height of the named font and have the font sizes of all the widgets on a page increase in size (including the ttk.Notebook tab captions). The user in question has vision problems. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Dec 15 11:50:25 2010 From: klappnase at web.de (Michael Lange) Date: Wed, 15 Dec 2010 11:50:25 +0100 Subject: [Tkinter-discuss] Ideas for user interface to allow users to change order of ttk.Notebook pages/tabs? In-Reply-To: <1292391012.4049.1410413553@webmail.messagingengine.com> References: <1292391012.4049.1410413553@webmail.messagingengine.com> Message-ID: <20101215115025.8a456cd0.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Wed, 15 Dec 2010 00:30:12 -0500: > I'm using the ttk.Notebook widget to manage a list of open files. > I create and destroy tabs as a user opens and closes files. > > I would like to offer my users a way to change the order of the > notebook tabs. Ideally I would like my users to be able to drag > and drop tabs like they do in Firefox, but I can't see a way to > do this with the events exposed by the Notebook widget. Since > drag and drop is not available to us, what do you think might be > an intuitive user (Tkinter/ttk-based) interface for allowing > users to reorder their tabs? > It should not be too hard to set up a drag and drop interface for this with Tkdnd. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You'll learn something about men and women -- the way they're supposed to be. Caring for each other, being happy with each other, being good to each other. That's what we call love. You'll like that a lot. -- Kirk, "The Apple", stardate 3715.6 From prog at vtr.net Wed Dec 15 14:49:18 2010 From: prog at vtr.net (craf) Date: Wed, 15 Dec 2010 10:49:18 -0300 Subject: [Tkinter-discuss] [Fwd: Change ttk.Notebook tab's font or font height?] Message-ID: <1292420958.4005.2.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: python at bdurham.com > Para: Python-Tkinter > Asunto: [Tkinter-discuss] Change ttk.Notebook tab's font or font > height? > Fecha: Wed, 15 Dec 2010 00:54:37 -0500 > > Is there a way to change the ttk.Notebook tab's font or font height? > > Use case: I would like to use a named font object for my tab captions > so a user can change the height of the named font and have the font > sizes of all the widgets on a page increase in size (including the > ttk.Notebook tab captions). The user in question has vision problems. > > Thank you, > Malcolm > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss Hi Malcom Here: http://code.activestate.com/recipes/541092-tknotebook/ here's how to create a class to create notebook. With a little patience can be converted for use with 8.5 tkinter.ttk and Python 3.1 Regards. Cristian From python at bdurham.com Wed Dec 15 15:28:51 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 09:28:51 -0500 Subject: [Tkinter-discuss] ttk.Notebook - how to bind to tab events (tab caption has focus or mouseover) Message-ID: <1292423331.13959.1410465129@webmail.messagingengine.com> I'm using the ttk.Notebook widget. What object do I bind to capture events related to specific tabs? I would like to trap when a tab caption gets keyboard focus ('') and when the mouse pointer is over a specific tab caption (''). I can trap mouse clicks on tabs (, ), but I can't find a way to determine what tab a user clicked on in the case of a right click. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Wed Dec 15 15:50:20 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 09:50:20 -0500 Subject: [Tkinter-discuss] [Fwd: Change ttk.Notebook tab's font or font height?] In-Reply-To: <1292420958.4005.2.camel@cristian-desktop> References: <1292420958.4005.2.camel@cristian-desktop> Message-ID: <1292424620.20812.1410478869@webmail.messagingengine.com> Cristian, > Here: http://code.activestate.com/recipes/541092-tknotebook/ > > Here's how to create a class to create notebook. With a little patience can be converted for use with 8.5 tkinter.ttk and Python 3.1 Thank you! Malcolm From klappnase at web.de Wed Dec 15 16:21:21 2010 From: klappnase at web.de (Michael Lange) Date: Wed, 15 Dec 2010 16:21:21 +0100 Subject: [Tkinter-discuss] ttk.Notebook - how to bind to tab events (tab caption has focus or mouseover) In-Reply-To: <1292423331.13959.1410465129@webmail.messagingengine.com> References: <1292423331.13959.1410465129@webmail.messagingengine.com> Message-ID: <20101215162121.6e33509f.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Wed, 15 Dec 2010 09:28:51 -0500: > I'm using the ttk.Notebook widget. What object do I bind to > capture events related to specific tabs? > > I would like to trap when a tab caption gets keyboard focus > ('') and when the mouse pointer is over a specific tab > caption (''). > Maybe you can use the <> virtual event instead? > I can trap mouse clicks on tabs (, ), but I > can't find a way to determine what tab a user clicked on in the > case of a right click. > Here's a brief example how to identify the tab which received the right-click; the same callback could be bound to Motion events which might be used as a replacement for the Enter event. ################################## from Tkinter import * import ttk root = Tk() nb = ttk.Notebook(root) nb.pack(fill='both', expand=1) t = Text(nb) nb.add(t, text='foo') c = Canvas(nb) nb.add(c, text='bar') def on_button_3(event): if event.widget.identify(event.x, event.y) == 'label': index = event.widget.index('@%d,%d' % (event.x, event.y)) print event.widget.tab(index, 'text') nb.bind('<3>', on_button_3) root.mainloop() ################################## Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Deflector shields just came on, Captain. From klappnase at web.de Wed Dec 15 16:44:09 2010 From: klappnase at web.de (Michael Lange) Date: Wed, 15 Dec 2010 16:44:09 +0100 Subject: [Tkinter-discuss] Change ttk.Notebook tab's font or font height? In-Reply-To: <1292392477.9462.1410415731@webmail.messagingengine.com> References: <1292392477.9462.1410415731@webmail.messagingengine.com> Message-ID: <20101215164409.ca7e9787.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Wed, 15 Dec 2010 00:54:37 -0500: > Is there a way to change the ttk.Notebook tab's font or font > height? > The following example seems to do what you want, at least unless you change the theme in use: ########################## from Tkinter import * import ttk import tkFont root = Tk() f = tkFont.Font(family='helvetica', size=-12) s = ttk.Style() s.configure('.', font=f) nb = ttk.Notebook(root) nb.pack(fill='both', expand=1) t = Text(nb, font=f) nb.add(t, text='foo') c = Canvas(nb) nb.add(c, text='bar') def toggle_font(event): if event.keysym == '0': f['size'] = -12 elif event.keysym == 'plus': if f['size'] > -31: f['size'] = f['size'] - 1 elif event.keysym == 'minus': if f['size'] < -6: f['size'] = f['size'] + 1 root.bind('', toggle_font) root.bind('', toggle_font) root.bind('', toggle_font) root.mainloop() ######################### Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Lots of people drink from the wrong bottle sometimes. -- Edith Keeler, "The City on the Edge of Forever", stardate unknown From python at bdurham.com Wed Dec 15 20:48:18 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 14:48:18 -0500 Subject: [Tkinter-discuss] ttk.Notebook - how to bind to tab events (tab caption has focus or mouseover) In-Reply-To: <20101215162121.6e33509f.klappnase@web.de> References: <1292423331.13959.1410465129@webmail.messagingengine.com> <20101215162121.6e33509f.klappnase@web.de> Message-ID: <1292442498.16189.1410527775@webmail.messagingengine.com> Michael, Thank you so much for your example!! Re: Detect mouse events on tabs. The trick for me was understanding how to use the index method. Your technique below is exactly the solution I was looking for (I wasn't aware of the '@%d,%d' formatting technique). index = event.widget.index('@%d,%d' % (event.x, event.y)) Re: Detect when a tab caption has keyboard focus ( or similar). The <> does not correspond to the tab caption gaining keyboard focus. And the notebook widget generates a single event when it gets focus. Is there a way to drill-down to the Tk label controls in the captions and bind to their events? Or is there a way to expose the tabs as actual widgets whose events can be bound to? Thanks again for all your help in these forums! Malcolm From python at bdurham.com Wed Dec 15 20:52:52 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 14:52:52 -0500 Subject: [Tkinter-discuss] Change ttk.Notebook tab's font or font height? In-Reply-To: <20101215164409.ca7e9787.klappnase@web.de> References: <1292392477.9462.1410415731@webmail.messagingengine.com> <20101215164409.ca7e9787.klappnase@web.de> Message-ID: <1292442772.17858.1410530191@webmail.messagingengine.com> Michael, > The following example seems to do what you want, at least unless you change the theme in use > > f = tkFont.Font(family='helvetica', size=-12) > s = ttk.Style() > s.configure('.', font=f) That is **exactly** what I was looking for. Once again, thank you so much for your help. Tkinter rocks! (who would have thought?!) Danke sehr!!! Malcolm From klappnase at web.de Wed Dec 15 22:00:41 2010 From: klappnase at web.de (Michael Lange) Date: Wed, 15 Dec 2010 22:00:41 +0100 Subject: [Tkinter-discuss] ttk.Notebook - how to bind to tab events (tab caption has focus or mouseover) In-Reply-To: <1292442498.16189.1410527775@webmail.messagingengine.com> References: <1292423331.13959.1410465129@webmail.messagingengine.com> <20101215162121.6e33509f.klappnase@web.de> <1292442498.16189.1410527775@webmail.messagingengine.com> Message-ID: <20101215220041.c42c3e8e.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Wed, 15 Dec 2010 14:48:18 -0500: (...) > > Re: Detect when a tab caption has keyboard focus ( or similar). > > The <> does not correspond to the tab caption > gaining keyboard focus. > > And the notebook widget generates a single event when it gets > focus. > > Is there a way to drill-down to the Tk label controls in the captions > and bind to their events? Or is there a way to expose the tabs > as actual widgets whose events can be bound to? I don't think this is possible, it looks like the notebook widget itself is one window that catches the event and decides what to do - draw the focus indicator onto the next tab or pass the focus to another window. But, a far as I see, at least here with IceWm any time a tab receives the keyboard focus it will be selected as well, so maybe you can play around with the select mechanism, depending on what exactly you want to achieve. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Each kiss is as the first. -- Miramanee, Kirk's wife, "The Paradise Syndrome", stardate 4842.6 From python at bdurham.com Wed Dec 15 22:22:02 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 16:22:02 -0500 Subject: [Tkinter-discuss] Very interesting code sample: A Ttk Notebook with close buttons Message-ID: <1292448122.12796.1410541597@webmail.messagingengine.com> In researching how to determine when a ttk.Notebook tab caption has keyboard focus (still no luck), I stumbled across this code snippet which allows you to add Firefox-like close controls to your ttk.Notebook tabs. The close controls are added to the tab components via styles - they are not grafted on widgets that are place()-ed above controls. Here's the copy and paste code for Python 3.1; the usual Tkinter/ttk import statements need to be adjusted for Python 2.7. http://www.java2s.com/Open-Source/Python/3.1.2-Python/Demo/Demo/t kinter/ttk/notebook_closebtn.py.htm Note: You need to supply 3 close button gif files. I created 3 16x16 solid gif files in MS Paint so I could see the code in use. What is so cool about this example is that it uses the following methods to "drill-into" the Notebook and child Tab widgets to really customize the appearance and behavior of these widgets (capabilities that I didn't think existed in ttk). style.element_create( ... ) style.layout( ... ) elem = widget.identify(x, y) <--- allows one to examine child components I can't admit to understanding this code snippet, but I'm blown away with the capabilities of ttk. If anyone figures out this code, I would be curious how difficult it would be to implement the following Firefox like behaviors: - only show close buttons on the active tab vs. on all tabs - show an arrow image above a tabs' left or right edge to indicate the position of a dragged tab Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Wed Dec 15 22:31:42 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 15 Dec 2010 16:31:42 -0500 Subject: [Tkinter-discuss] ttk.Notebook - how to bind to tab events (tab caption has focus or mouseover) In-Reply-To: <20101215220041.c42c3e8e.klappnase@web.de> References: <1292423331.13959.1410465129@webmail.messagingengine.com><20101215162121.6e33509f.klappnase@web.de><1292442498.16189.1410527775@webmail.messagingengine.com> <20101215220041.c42c3e8e.klappnase@web.de> Message-ID: <1292448702.15742.1410545839@webmail.messagingengine.com> Michael, >> Is there a way to drill-down to the Tk label controls in the captions >> and bind to their events? Or is there a way to expose the tabs >> as actual widgets whose events can be bound to? > I don't think this is possible, it looks like the notebook widget itself > is one window that catches the event and decides what to do - draw > the focus indicator onto the next tab or pass the focus to another window. > But, a far as I see, at least here with IceWm any time a tab receives the > keyboard focus it will be selected as well, so maybe you can play around > with the select mechanism, depending on what exactly you want to achieve. Thank you for taking the time to investigate this behavior. I just posted an advanced example of a ttk.Notebook with close controls on the tabs. Apparently, it is possible to drill down into the child tab controls of the ttk Notebook using out-of-the-box ttk (without resorting to tcl magic). I'm studying this example now to see what may be possible regarding raising a got focus event for individual tab widgets ... as well as other advanced capabilities as well. Cool stuff!! Malcolm From prog at vtr.net Wed Dec 15 23:23:05 2010 From: prog at vtr.net (craf) Date: Wed, 15 Dec 2010 19:23:05 -0300 Subject: [Tkinter-discuss] as close windows by separate modules Message-ID: <1292451785.6651.8.camel@cristian-desktop> Hi. I have two modules: main.py--------------------- from tkinter import * from tkinter import ttk from code import Option class App: def __init__(self, master): master.protocol("WM_DELETE_WINDOW",Option.quit) master = Tk() master.geometry('640x480') app = App(master) master.mainloop() code.py--------------------- from tkinter import messagebox from tkinter import * from tkinter import ttk class Option: def quit(): if messagebox.askyesno(message='Close window'): master.quit() I want to press the close button and close the main window to run the module main.py. But I can not, the error it throws is: "NameError: global name 'master' is not defined" I appreciate any suggestions. Regards. Cristia Abarz?a From davecortesi at gmail.com Thu Dec 16 23:29:24 2010 From: davecortesi at gmail.com (David Cortesi) Date: Thu, 16 Dec 2010 14:29:24 -0800 Subject: [Tkinter-discuss] experimental tk program in python3 Message-ID: http://snippets.dzone.com/posts/show/12755 """ Program to do dynamic experimentation with the various padding and border properties of a ttk.Frame. A frame is created and populated with three sub-frames: 1. A set of spinboxes that adust the various padding parameters. 2. A set of controls to adjust the border style and width 3. A set of checkbuttons to alter the sticky values. By changing different values you can arrive at a preferred appearance. """ Comments on style & usage welcome (here, or added to the dzone snippet). dave cortesi From python at bdurham.com Fri Dec 17 00:07:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 16 Dec 2010 18:07:27 -0500 Subject: [Tkinter-discuss] experimental tk program in python3 In-Reply-To: References: Message-ID: <1292540847.25955.1410746401@webmail.messagingengine.com> Dave, Works in Python 2.7 by changing import statements to: from Tkinter import * import ttk Is there a way to change a frame's border color? (I think this is a Tkinter limitation, but I'd love to be proven wrong) I don't think your border width spinner updates the border? Nice to have additions? 1. A 'Reset' button to reset the form to its original values. 2. A 'Copy to clipboard' option that creates a line of code that matches the current frame layout and places it on the clipboard. Malcolm From prog at vtr.net Fri Dec 17 04:35:36 2010 From: prog at vtr.net (craf) Date: Fri, 17 Dec 2010 00:35:36 -0300 Subject: [Tkinter-discuss] Calling functions outside the class Message-ID: <1292556936.5237.5.camel@cristian-desktop> Hi. I'm testing this code: ------------------------------------------------------------------- from Tkinter import * class MyApp: def __init__(self, parent): self.myParent = parent ### (7) remember my parent, the root self.myContainer1 = Frame(parent) self.myContainer1.pack() self.button1 = Button(self.myContainer1) self.button1.configure(text="OK", background= "green") self.button1.pack(side=LEFT) self.button1.bind("", self.button1Click) ### (1) self.button2 = Button(self.myContainer1) self.button2.configure(text="Cancel", background="red") self.button2.pack(side=RIGHT) self.button2.bind("", self.button2Click) ### (2) def button1Click(self, event): ### (3) if self.button1["background"] == "green": ### (4) self.button1["background"] = "yellow" else: self.button2["background"] = "green" def button2Click(self, event): ### (5) self.myParent.destroy() ### (6) root = Tk() myapp = MyApp(root) root.mainloop() --------------------------------------------------------------------- Works without problems, but if I want to get the functions of the class, then the problems begin. from Tkinter import * class MyApp: def __init__(self, parent): self.myParent = parent ### (7) remember my parent, the root self.myContainer1 = Frame(parent) self.myContainer1.pack() self.button1 = Button(self.myContainer1) self.button1.configure(text="OK", background= "green") self.button1.pack(side=LEFT) self.button1.bind("", self.button1Click) ### (1) self.button2 = Button(self.myContainer1) self.button2.configure(text="Cancel", background="red") self.button2.pack(side=RIGHT) self.button2.bind("", self.button2Click) ### (2) def button1Click(self, event): ???FUNCTION OUTSIDE THE CLASS!!! if self.button1["background"] == "green": ### (4) self.button1["background"] = "yellow" else: self.button2["background"] = "green" def button2Click(self, event): ???FUNCTION OUTSIDE THE CLASS!!! self.myParent.destroy() ### (6) root = Tk() myapp = MyApp(root) root.mainloop() What would be the correct way to call them? Thanks in advance Regards Cristian Abarzua F From michael.odonnell at uam.es Fri Dec 17 09:03:28 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Fri, 17 Dec 2010 09:03:28 +0100 Subject: [Tkinter-discuss] Calling functions outside the class In-Reply-To: <1292556936.5237.5.camel@cristian-desktop> References: <1292556936.5237.5.camel@cristian-desktop> Message-ID: Hi Cristian, The problem is, self is only defined within the class definition. Basically, the function are not part of the class, just called by the class. We use a lambda to get the class passed to the function. So, to correct your code: from Tkinter import * class MyApp: def __init__(self, parent): self.myParent = parent ### (7) remember my parent, the root self.myContainer1 = Frame(parent) self.myContainer1.pack() self.button1 = Button(self.myContainer1) self.button1.configure(text="OK", background= "green") self.button1.pack(side=LEFT) self.button1.bind("", lambda e, win=self: button1Click(win)) ### (1) self.button2 = Button(self.myContainer1) self.button2.configure(text="Cancel", background="red") self.button2.pack(side=RIGHT) self.button2.bind("", lambda e, win=self: button2Click(win)) ### (2) def button1Click(win): if win.button1["background"] == "green": ### (4) win.button1["background"] = "yellow" else: win.button2["background"] = "green" def button2Click(win): win.myParent.destroy() ### (6) root = Tk() myapp = MyApp(root) root.mainloop() root = Tk() myapp = MyApp(root) root.mainloop() On Fri, Dec 17, 2010 at 4:35 AM, craf wrote: > Hi. > > I'm testing this code: > > ------------------------------------------------------------------- > from Tkinter import * > > class MyApp: > ? ?def __init__(self, parent): > ? ? ? ?self.myParent = parent ?### (7) remember my parent, the root > ? ? ? ?self.myContainer1 = Frame(parent) > ? ? ? ?self.myContainer1.pack() > > ? ? ? ?self.button1 = Button(self.myContainer1) > ? ? ? ?self.button1.configure(text="OK", background= "green") > ? ? ? ?self.button1.pack(side=LEFT) > ? ? ? ?self.button1.bind("", self.button1Click) ### (1) > > ? ? ? ?self.button2 = Button(self.myContainer1) > ? ? ? ?self.button2.configure(text="Cancel", background="red") > ? ? ? ?self.button2.pack(side=RIGHT) > ? ? ? ?self.button2.bind("", self.button2Click) ### (2) > > ? ?def button1Click(self, event): ? ?### (3) > ? ? ? ?if self.button1["background"] == "green": ### (4) > ? ? ? ? ? ?self.button1["background"] = "yellow" > ? ? ? ?else: > ? ? ? ? ? ?self.button2["background"] = "green" > > ? ?def button2Click(self, event): ?### (5) > ? ? ? ?self.myParent.destroy() ? ? ### (6) > > > root = Tk() > myapp = MyApp(root) > root.mainloop() > > --------------------------------------------------------------------- > > Works without problems, but if I want to get the functions of the class, > then the problems begin. > > from Tkinter import * > > class MyApp: > ? ?def __init__(self, parent): > ? ? ? ?self.myParent = parent ?### (7) remember my parent, the root > ? ? ? ?self.myContainer1 = Frame(parent) > ? ? ? ?self.myContainer1.pack() > > ? ? ? ?self.button1 = Button(self.myContainer1) > ? ? ? ?self.button1.configure(text="OK", background= "green") > ? ? ? ?self.button1.pack(side=LEFT) > ? ? ? ?self.button1.bind("", self.button1Click) ### (1) > > ? ? ? ?self.button2 = Button(self.myContainer1) > ? ? ? ?self.button2.configure(text="Cancel", background="red") > ? ? ? ?self.button2.pack(side=RIGHT) > ? ? ? ?self.button2.bind("", self.button2Click) ### (2) > > def button1Click(self, event): ? ????FUNCTION OUTSIDE THE CLASS!!! > ? ?if self.button1["background"] == "green": ### (4) > ? ? ? ?self.button1["background"] = "yellow" > ? ?else: > ? ? ? ?self.button2["background"] = "green" > > def button2Click(self, event): ???FUNCTION OUTSIDE THE CLASS!!! > ? ? ? ?self.myParent.destroy() ? ? ### (6) > > > root = Tk() > myapp = MyApp(root) > root.mainloop() > > What would be the correct way to call them? > > Thanks in advance > > Regards > > Cristian Abarzua F > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From prog at vtr.net Fri Dec 17 13:46:57 2010 From: prog at vtr.net (craf) Date: Fri, 17 Dec 2010 09:46:57 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Calling functions outside the class] Message-ID: <1292590017.3340.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael O'Donnell > Para: craf > Cc: Python Tkinter Ingles > Asunto: Re: [Tkinter-discuss] Calling functions outside the class > Fecha: Fri, 17 Dec 2010 09:03:28 +0100 > > Hi Cristian, > > The problem is, self is only defined within the class definition. > Basically, the function are not part of the class, just called by the class. > We use a lambda to get the class passed to the function. > So, to correct your code: > > from Tkinter import * > > class MyApp: > def __init__(self, parent): > self.myParent = parent ### (7) remember my parent, the root > self.myContainer1 = Frame(parent) > self.myContainer1.pack() > > self.button1 = Button(self.myContainer1) > self.button1.configure(text="OK", background= "green") > self.button1.pack(side=LEFT) > self.button1.bind("", lambda e, win=self: > button1Click(win)) ### (1) > > self.button2 = Button(self.myContainer1) > self.button2.configure(text="Cancel", background="red") > self.button2.pack(side=RIGHT) > self.button2.bind("", lambda e, win=self: > button2Click(win)) ### (2) > > def button1Click(win): > if win.button1["background"] == "green": ### (4) > win.button1["background"] = "yellow" > else: > win.button2["background"] = "green" > > def button2Click(win): > win.myParent.destroy() ### (6) > > > root = Tk() > myapp = MyApp(root) > root.mainloop() > > > root = Tk() > myapp = MyApp(root) > root.mainloop() > > > > > On Fri, Dec 17, 2010 at 4:35 AM, craf wrote: > > Hi. > > > > I'm testing this code: > > > > ------------------------------------------------------------------- > > from Tkinter import * > > > > class MyApp: > > def __init__(self, parent): > > self.myParent = parent ### (7) remember my parent, the root > > self.myContainer1 = Frame(parent) > > self.myContainer1.pack() > > > > self.button1 = Button(self.myContainer1) > > self.button1.configure(text="OK", background= "green") > > self.button1.pack(side=LEFT) > > self.button1.bind("", self.button1Click) ### (1) > > > > self.button2 = Button(self.myContainer1) > > self.button2.configure(text="Cancel", background="red") > > self.button2.pack(side=RIGHT) > > self.button2.bind("", self.button2Click) ### (2) > > > > def button1Click(self, event): ### (3) > > if self.button1["background"] == "green": ### (4) > > self.button1["background"] = "yellow" > > else: > > self.button2["background"] = "green" > > > > def button2Click(self, event): ### (5) > > self.myParent.destroy() ### (6) > > > > > > root = Tk() > > myapp = MyApp(root) > > root.mainloop() > > > > --------------------------------------------------------------------- > > > > Works without problems, but if I want to get the functions of the class, > > then the problems begin. > > > > from Tkinter import * > > > > class MyApp: > > def __init__(self, parent): > > self.myParent = parent ### (7) remember my parent, the root > > self.myContainer1 = Frame(parent) > > self.myContainer1.pack() > > > > self.button1 = Button(self.myContainer1) > > self.button1.configure(text="OK", background= "green") > > self.button1.pack(side=LEFT) > > self.button1.bind("", self.button1Click) ### (1) > > > > self.button2 = Button(self.myContainer1) > > self.button2.configure(text="Cancel", background="red") > > self.button2.pack(side=RIGHT) > > self.button2.bind("", self.button2Click) ### (2) > > > > def button1Click(self, event): ???FUNCTION OUTSIDE THE CLASS!!! > > if self.button1["background"] == "green": ### (4) > > self.button1["background"] = "yellow" > > else: > > self.button2["background"] = "green" > > > > def button2Click(self, event): ???FUNCTION OUTSIDE THE CLASS!!! > > self.myParent.destroy() ### (6) > > > > > > root = Tk() > > myapp = MyApp(root) > > root.mainloop() > > > > What would be the correct way to call them? > > > > Thanks in advance > > > > Regards > > > > Cristian Abarzua F > > > > _______________________________________________ > > Tkinter-discuss mailing list > > Tkinter-discuss at python.org > > http://mail.python.org/mailman/listinfo/tkinter-discuss > > Hi Michael thank you very much by example. Now I understand. Regards. Cristian From klappnase at web.de Fri Dec 17 13:49:34 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 13:49:34 +0100 Subject: [Tkinter-discuss] experimental tk program in python3 In-Reply-To: <1292540847.25955.1410746401@webmail.messagingengine.com> References: <1292540847.25955.1410746401@webmail.messagingengine.com> Message-ID: <20101217134934.f670da25.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Thu, 16 Dec 2010 18:07:27 -0500: > Dave, > > Works in Python 2.7 by changing import statements to: > > from Tkinter import * > import ttk > > Is there a way to change a frame's border color? (I think this is a > Tkinter limitation, but I'd love to be proven wrong) > For widgets that don't accept keyboard focus you can use the highlightbackground option to create a colored border (although you cannot add a "3D"-relief this way): ############################# from Tkinter import * root = Tk() f = Frame(root, bg='white', highlightthickness=2, highlightbackground='red', width=200, height=200) f.pack(padx=100, pady=100, fill='both', expand=1) root.mainloop() ############################ .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You're too beautiful to ignore. Too much woman. -- Kirk to Yeoman Rand, "The Enemy Within", stardate unknown From python at bdurham.com Fri Dec 17 14:41:45 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 08:41:45 -0500 Subject: [Tkinter-discuss] experimental tk program in python3 In-Reply-To: <20101217134934.f670da25.klappnase@web.de> References: <1292540847.25955.1410746401@webmail.messagingengine.com> <20101217134934.f670da25.klappnase@web.de> Message-ID: <1292593305.14712.1410836105@webmail.messagingengine.com> Hi Michael, > For widgets that don't accept keyboard focus you can use the highlightbackground option to create a colored border (although you cannot add a "3D"-relief this way) ... I took your example and added another frame and widgets that gain focus. Your highlightbackground suggestion only works when there's a single frame without widgets that can gain focus themselves. Interesting: On my machine, the highlightbackground appears to work the opposite of its stated purpose, eg. when button2 has focus, frame 1 shows its highlightbackground and vice-versa. from Tkinter import * root = Tk() f1 = Frame(root, bg='white', highlightthickness=2, highlightbackground='red', width=200, height=200) f1.pack(padx=100, pady=100, fill='both', expand=1) Button( f1, text='Button 1' ).pack() f2 = Frame(root, bg='white', highlightthickness=2, highlightbackground='green', width=200, height=200) f2.pack(padx=100, pady=100, fill='both', expand=1) Button( f2, text='Button 2' ).pack() root.mainloop() I'm going to start a new thread on the topic of creating frames with custom border colors. Regards, Malcolm From python at bdurham.com Fri Dec 17 15:00:08 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 09:00:08 -0500 Subject: [Tkinter-discuss] Techniques for creating the appearance of frames with custom border colors Message-ID: <1292594408.20452.1410837847@webmail.messagingengine.com> I understand that Tkinter frames do not have a property that allows their border color to be customized. Here are some high level ideas I have on how to create a colored border effect - any suggestions on best practice appreciated. 1. Turn off the frame's border. Enclose the frame in a parent frame also without a border. Set the parent frame's background color to the color of the border you want. Make sure the parent frame's layout options (grid/pack) match the inner frame's options. 2. Use a canvas instead of a frame, draw a border using the create_rectangle( ..., fill="" ), and then bind to the canvas's (?) event and to delete and redraw the border every time the canvas resizes. 3. Use a tk.call( ... ) to gain access to the TCL interpreter and its richer set of capabilies? Regarding options 2 and 3: Might there be a way to create non-solid border styles, eg. borders that are composed of dots or dashes? Thanks for your ideas, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Dec 17 15:10:09 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 15:10:09 +0100 Subject: [Tkinter-discuss] experimental tk program in python3 In-Reply-To: <1292593305.14712.1410836105@webmail.messagingengine.com> References: <1292540847.25955.1410746401@webmail.messagingengine.com> <20101217134934.f670da25.klappnase@web.de> <1292593305.14712.1410836105@webmail.messagingengine.com> Message-ID: <20101217151009.f9a8fb29.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Fri, 17 Dec 2010 08:41:45 -0500: > Hi Michael, > > > For widgets that don't accept keyboard focus you can use the > > highlightbackground option to create a colored border (although you > > cannot add a "3D"-relief this way) ... > > I took your example and added another frame and widgets that gain focus. > Your highlightbackground suggestion only works when there's a single > frame without widgets that can gain focus themselves. Interesting: On my > machine, the highlightbackground appears to work the opposite of its > stated purpose, eg. when button2 has focus, frame 1 shows its > highlightbackground and vice-versa. > Oh yes, I failed to check this properly; you can fix this by additionally setting the highlightcolor though: ########################## from Tkinter import * root = Tk() f1 = Frame(root, bg='white', highlightthickness=2, highlightbackground='red', highlightcolor='red', width=200, height=200) f1.pack(padx=100, pady=100, fill='both', expand=1) Button( f1, text='Button 1' ).pack() f2 = Frame(root, bg='white', highlightthickness=2, highlightbackground='green', width=200, height=200) f2.pack(padx=100, pady=100, fill='both', expand=1) Button( f2, text='Button 2' ).pack() root.mainloop() ########################## Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Another war ... must it always be so? How many comrades have we lost in this way? ... Obedience. Duty. Death, and more death ... -- Romulan Commander, "Balance of Terror", stardate 1709.2 From waynejwerner at gmail.com Fri Dec 17 15:22:35 2010 From: waynejwerner at gmail.com (Wayne Werner) Date: Fri, 17 Dec 2010 08:22:35 -0600 Subject: [Tkinter-discuss] Techniques for creating the appearance of frames with custom border colors In-Reply-To: <1292594408.20452.1410837847@webmail.messagingengine.com> References: <1292594408.20452.1410837847@webmail.messagingengine.com> Message-ID: On Fri, Dec 17, 2010 at 8:00 AM, wrote: > I understand that Tkinter frames do not have a property that allows their > border color to be customized. > > Here are some high level ideas I have on how to create a colored border > effect - any suggestions on best practice appreciated. > > 2. Use a canvas instead of a frame, draw a border using the > create_rectangle( ..., fill="" ), and then bind to > the canvas's (?) event and to delete and redraw the border every > time the canvas resizes. > > Regarding options 2 and 3: Might there be a way to create non-solid border > styles, eg. borders that are composed of dots or dashes? > on 2, definitely. Rather than using fill, you could set the outline color, style, and width (e.g. dash/stipple): http://effbot.org/tkinterbook/canvas.htm HTH, Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From ozgulfirat at gmail.com Fri Dec 17 15:28:02 2010 From: ozgulfirat at gmail.com (Firat Ozgul) Date: Fri, 17 Dec 2010 16:28:02 +0200 Subject: [Tkinter-discuss] as close windows by separate modules Message-ID: Check the following out. code.py ------------ from tkinter import messagebox from tkinter import * from tkinter import ttk class Option: def quit(master): if messagebox.askyesno(message='Close window'): master.quit() main.py ----------- from tkinter import * from tkinter import ttk from code import Option class App: def __init__(self, master): master.protocol("WM_DELETE_WINDOW", lambda: Option.quit(master)) master = Tk() master.geometry('640x480') app = App(master) master.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Fri Dec 17 15:35:42 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 09:35:42 -0500 Subject: [Tkinter-discuss] experimental tk program in python3 In-Reply-To: <20101217151009.f9a8fb29.klappnase@web.de> References: <1292540847.25955.1410746401@webmail.messagingengine.com><20101217134934.f670da25.klappnase@web.de><1292593305.14712.1410836105@webmail.messagingengine.com> <20101217151009.f9a8fb29.klappnase@web.de> Message-ID: <1292596542.32372.1410843993@webmail.messagingengine.com> Michael, Ah, I see! The trick seems to be: - don't set a frame's border width or relief properties (or reset them to 0 and 'flat') - set highlightcolor= - set highlightbackground= - set highlightthickness= I think that also answers the question I just posted regarding how to create the appearance of colored frame borders. Thank you (one answer for 2 questions!) Regards, Malcolm From: "Michael Lange" from Tkinter import * root = Tk() f1 = Frame(root, bg='white', highlightthickness=2, highlightbackground='red', highlightcolor='red', width=200, height=200) f1.pack(padx=100, pady=100, fill='both', expand=1) Button( f1, text='Button 1' ).pack() f2 = Frame(root, bg='white', highlightthickness=2, highlightbackground='green', width=200, height=200) f2.pack(padx=100, pady=100, fill='both', expand=1) Button( f2, text='Button 2' ).pack() root.mainloop() From python at bdurham.com Fri Dec 17 15:38:25 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 09:38:25 -0500 Subject: [Tkinter-discuss] Techniques for creating the appearance of frames with custom border colors In-Reply-To: References: <1292594408.20452.1410837847@webmail.messagingengine.com> Message-ID: <1292596705.475.1410845303@webmail.messagingengine.com> > On 2, definitely. Rather than using fill, you could set the outline color, style, and width (e.g. dash/stipple): [1]> http://effbot.org/tkinterbook/canvas.htm Thanks Wayne, Malcolm References 1. http://effbot.org/tkinterbook/canvas.htm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Dec 17 15:49:58 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 15:49:58 +0100 Subject: [Tkinter-discuss] Techniques for creating the appearance of frames with custom border colors In-Reply-To: <1292594408.20452.1410837847@webmail.messagingengine.com> References: <1292594408.20452.1410837847@webmail.messagingengine.com> Message-ID: <20101217154958.ea5d38d3.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Fri, 17 Dec 2010 09:00:08 -0500: > I understand that Tkinter frames do not have a property that > allows their border color to be customized. > > Here are some high level ideas I have on how to create a colored > border effect - any suggestions on best practice appreciated. > > 1. Turn off the frame's border. Enclose the frame in a parent > frame also without a border. Set the parent frame's background > color to the color of the border you want. Make sure the parent > frame's layout options (grid/pack) match the inner frame's > options. > > 2. Use a canvas instead of a frame, draw a border using the > create_rectangle( ..., fill="" ), and then > bind to the canvas's (?) event and to delete and redraw > the border every time the canvas resizes. > > 3. Use a tk.call( ... ) to gain access to the TCL interpreter and > its richer set of capabilies? > > Regarding options 2 and 3: Might there be a way to create > non-solid border styles, eg. borders that are composed of dots or > dashes? I don't think there are such options in Tk by default, so 3. probably is not an option (unless you do very fancy things with ttk styles, but these are probably also possible with the ttk module). With a canvas you can try something like: ################### from Tkinter import * root = Tk() root.geometry('500x500') c = Canvas(root, bg='yellow', bd=0, highlightthickness=0, takefocus=0) c.pack(fill='both', expand=1, padx=100, pady=100) c.update_idletasks() w, h = c.winfo_width(), c.winfo_height() r = c.create_rectangle(0, 0, w-1, h-1, outline='red', fill='', dash=(5,5)) f = Frame(c, width=w-2, height=h-2) w = c.create_window(1, 1, window=f, anchor='nw') def foo(event): w, h = event.width, event.height event.widget.coords(r, 0, 0, w-1, h-1) f.configure(width=w-2, height=h-2) c.bind('', foo) root.mainloop() ################### This seems to werk ok, I'm not sure if this might break in some situations though. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. The only solution is ... a balance of power. We arm our side with exactly that much more. A balance of power -- the trickiest, most difficult, dirtiest game of them all. But the only one that preserves both sides. -- Kirk, "A Private Little War", stardate 4211.8 From python at bdurham.com Fri Dec 17 18:04:18 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 12:04:18 -0500 Subject: [Tkinter-discuss] Techniques for creating the appearance of frames with custom border colors In-Reply-To: <20101217154958.ea5d38d3.klappnase@web.de> References: <1292594408.20452.1410837847@webmail.messagingengine.com> <20101217154958.ea5d38d3.klappnase@web.de> Message-ID: <1292605458.18523.1410868895@webmail.messagingengine.com> Michael, Your code works wonderfully - thank you very much!! One question: Why did you add your inner frame to the canvas as a window via c.create_window() vs. just packing the frame? I tried the frame packing technique per the following code change (replacing c.createwindow with pack): f = Frame(c, width=w-2, height=h-2) # w = c.create_window(1, 1, window=f, anchor='nw') f.pack() # note: will not work if passed fill='both', expand=1 And the code seemed to work with the following caveats: - the top row of the rectangle is not displayed (I can't figure this one out) - screen redraws seem (subjectively) to be less efficient (yellow background bleeds through) Regards, Malcolm From: "Michael Lange" I don't think there are such options in Tk by default, so 3. probably is not an option (unless you do very fancy things with ttk styles, but these are probably also possible with the ttk module). With a canvas you can try something like: from Tkinter import * root = Tk() root.geometry('500x500') c = Canvas(root, bg='yellow', bd=0, highlightthickness=0, takefocus=0) c.pack(fill='both', expand=1, padx=100, pady=100) c.update_idletasks() w, h = c.winfo_width(), c.winfo_height() r = c.create_rectangle(0, 0, w-1, h-1, outline='red', fill='', dash=(5,5)) f = Frame(c, width=w-2, height=h-2) w = c.create_window(1, 1, window=f, anchor='nw') def foo(event): w, h = event.width, event.height event.widget.coords(r, 0, 0, w-1, h-1) f.configure(width=w-2, height=h-2) c.bind('', foo) root.mainloop() This seems to work ok, I'm not sure if this might break in some situations though. From python at bdurham.com Fri Dec 17 18:27:41 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 12:27:41 -0500 Subject: [Tkinter-discuss] When to use .update() vs. update_idletasks()? Message-ID: <1292606861.25674.1410872441@webmail.messagingengine.com> Looking for some advice on when to use .update() vs. update_idletasks(). Are there use cases that favor the use of one of these techniques vs. the other? Are there situations where one of these techniques should always or never be used? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Dec 17 18:27:52 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 18:27:52 +0100 Subject: [Tkinter-discuss] Techniques for creating the appearance of frames with custom border colors In-Reply-To: <1292605458.18523.1410868895@webmail.messagingengine.com> References: <1292594408.20452.1410837847@webmail.messagingengine.com> <20101217154958.ea5d38d3.klappnase@web.de> <1292605458.18523.1410868895@webmail.messagingengine.com> Message-ID: <20101217182752.870434e5.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Fri, 17 Dec 2010 12:04:18 -0500: > Michael, > > Your code works wonderfully - thank you very much!! > > One question: Why did you add your inner frame to the canvas as a window > via c.create_window() vs. just packing the frame? > To be honest, for no special reason, it seemed the "natural choice" to me :) BTW, in my example I did frame.configure(width=...) in the event binding, which at a second glance I would replace with canvas.itemconfigure (w, width=event.width-2...) A real advantage of the window items vs. pack() might be that it is probably easier to handle when there are multiple widgets placed in the canvas. > I tried the frame packing technique per the following code change > (replacing c.createwindow with pack): > > f = Frame(c, width=w-2, height=h-2) > # w = c.create_window(1, 1, window=f, anchor='nw') > f.pack() # note: will not work if passed fill='both', expand=1 > > And the code seemed to work with the following caveats: > > - the top row of the rectangle is not displayed (I can't figure this one > out) You can avoid this with pack(pady=(1,0)) Regards Michael From python at bdurham.com Fri Dec 17 18:29:43 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 12:29:43 -0500 Subject: [Tkinter-discuss] Stipple use cases and/or examples? Message-ID: <1292606983.26041.1410874701@webmail.messagingengine.com> I've seen the term "stipple" mentioned in recent posts. The Tkinter documentation is woefully short on details here. I've googled for examples and found very few. For those with the same question as me, here's one example. http://infohost.nmt.edu/tcc/help/pubs/tkinter/std-attrs.html My question is what are typical use cases for stipples and do you use the built-in gray12...gray75 stipples (are there others?) or build your own (and why?). If anyone wants to post and example of a stipple in use, I would appreciate it. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Dec 17 18:45:17 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 18:45:17 +0100 Subject: [Tkinter-discuss] When to use .update() vs. update_idletasks()? In-Reply-To: <1292606861.25674.1410872441@webmail.messagingengine.com> References: <1292606861.25674.1410872441@webmail.messagingengine.com> Message-ID: <20101217184517.a350ddc8.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Fri, 17 Dec 2010 12:27:41 -0500: > Looking for some advice on when to use .update() vs. > update_idletasks(). Are there use cases that favor the use of one > of these techniques vs. the other? Are there situations where one > of these techniques should always or never be used? > As a rule of thumb I'd say : *never* use update() unless you really need it. If update_idletasks() does the job, it is to be preferred. Regards Michael From python at bdurham.com Fri Dec 17 18:52:19 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 12:52:19 -0500 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? Message-ID: <1292608339.1589.1410876097@webmail.messagingengine.com> This question is related to using Canvases and Frames as containers and does not consider the drawing capabilities of the Canvas widget. Canvas and Frames are both containers. My understanding is that both of these containers provide identical layout behaviors via their pack, grid, and place methods (is this really true?). In other words, I should be able to replace a Frame with a Canvas and have identical behavior, correct? >From a container perspective, would it be correct to describe a Canvas as an enhanced Frame with the following capabilities? - the ability to support virtual sizes greater than the visible display area - the scrollbar, scroll and viewport features associated with having a larger virtual display area One of my points of confusion with Canvas containers is figuring out what techniques to use for the layout of traditional widgets. Can I use regular pack and grid placement always, only when a canvas does not have scrolling, or never? When should one use the create_window() technique for widget placement? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Fri Dec 17 18:56:22 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 12:56:22 -0500 Subject: [Tkinter-discuss] When to use .update() vs. update_idletasks()? In-Reply-To: <20101217184517.a350ddc8.klappnase@web.de> References: <1292606861.25674.1410872441@webmail.messagingengine.com> <20101217184517.a350ddc8.klappnase@web.de> Message-ID: <1292608582.2856.1410879013@webmail.messagingengine.com> > As a rule of thumb I'd say: *never* use update() unless you really need it. If update_idletasks() does the job, it is to be preferred. Thanks Michael, that's a great tip. Malcolm From michael.odonnell at uam.es Fri Dec 17 19:14:27 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Fri, 17 Dec 2010 19:14:27 +0100 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: <1292608339.1589.1410876097@webmail.messagingengine.com> References: <1292608339.1589.1410876097@webmail.messagingengine.com> Message-ID: Hi Malcom, I have never heard of packing widgets within a canvas. Just use create_window, so there is no automatic placement, you need to handle all placement. Note with the following, packing a label within a canvas: from Tkinter import * root = Tk() c=Canvas(root, bg="red", width=400, height=400) c.pack() d=Label(c, text="Hello") d.pack() root.mainloop() The Label widget in fact REPLACES the canvas in the display rather than being packed within it. I don't know why (try commenting out the d.pack() line) and see the difference.) Mick On Fri, Dec 17, 2010 at 6:52 PM, wrote: > This question is related to using Canvases and Frames as containers and does > not consider the drawing capabilities of the Canvas widget. > > Canvas and Frames are both containers. My understanding is that both of > these containers provide identical layout behaviors via their pack, grid, > and place methods (is this really true?). In other words, I should be able > to replace a Frame with a Canvas and have identical behavior, correct? > > From a container perspective, would it be correct to describe a Canvas as an > enhanced Frame with the following capabilities? > > - the ability to support virtual sizes greater than the visible display area > - the scrollbar, scroll and viewport features associated with having a > larger virtual display area > > One of my points of confusion with Canvas containers is figuring out what > techniques to use for the layout of traditional widgets. Can I use regular > pack and grid placement always, only when a canvas does not have scrolling, > or never? When should one use the create_window() technique for widget > placement? > > Thank you, > Malcolm > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From prog at vtr.net Fri Dec 17 19:16:22 2010 From: prog at vtr.net (craf) Date: Fri, 17 Dec 2010 15:16:22 -0300 Subject: [Tkinter-discuss] lambda function to simplify Message-ID: <1292609782.5645.7.camel@cristian-desktop> Hi. According to this code.... ------------------------------------------------------------------ import Tkinter class App: def __init__(self, master): self.root = master self.b1 = Tkinter.Button(master) self.b1.pack() self.b1.bind('', lambda e,widget=self:greeting(widget)) self.root.protocol('WM_DELETE_WINDOW', lambda:((lambda e, widget=self:greeting(widget))(self.root))) def greeting(widget): widget.root.destroy() master = Tkinter.Tk() master.geometry('400x400') app = App(master) master.mainloop() ------------------------------------------------------------------- I have access to the function (greeting) from the button and the window close button. It works fine, but wanted to know whether the use of lambda (lambda), can be expressed in another way more elegant and less confusing. Regards. Cristian Abarzua From klappnase at web.de Fri Dec 17 20:48:17 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 20:48:17 +0100 Subject: [Tkinter-discuss] When to use .update() vs. update_idletasks()? In-Reply-To: <1292608582.2856.1410879013@webmail.messagingengine.com> References: <1292606861.25674.1410872441@webmail.messagingengine.com> <20101217184517.a350ddc8.klappnase@web.de> <1292608582.2856.1410879013@webmail.messagingengine.com> Message-ID: <20101217204817.70c2761d.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Fri, 17 Dec 2010 12:56:22 -0500: > > As a rule of thumb I'd say: *never* use update() unless you really > > need it. If update_idletasks() does the job, it is to be preferred. > BTW, for those who want to read more about update() vs. update_idletasks(), there are two pages on the tcl'ers wiki that discuss the potential problems with the update() method in more detail: http://wiki.tcl.tk/1252 http://wiki.tcl.tk/1255 Regards Michael From python at bdurham.com Fri Dec 17 21:00:09 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 15:00:09 -0500 Subject: [Tkinter-discuss] When to use .update() vs. update_idletasks()? In-Reply-To: <20101217204817.70c2761d.klappnase@web.de> References: <1292606861.25674.1410872441@webmail.messagingengine.com><20101217184517.a350ddc8.klappnase@web.de><1292608582.2856.1410879013@webmail.messagingengine.com> <20101217204817.70c2761d.klappnase@web.de> Message-ID: <1292616009.11088.1410898731@webmail.messagingengine.com> Michael, > BTW, for those who want to read more about update() vs. update_idletasks(), there are two pages on the tcl'ers wiki that discuss the potential problems with the update() method in more detail: > > http://wiki.tcl.tk/1252 > http://wiki.tcl.tk/1255 Excellent resources. Thank you, Malcolm From klappnase at web.de Fri Dec 17 21:53:08 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 21:53:08 +0100 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: References: <1292608339.1589.1410876097@webmail.messagingengine.com> Message-ID: <20101217215308.e4dd7ccc.klappnase@web.de> Hi, Thus spoketh "Michael O'Donnell" unto us on Fri, 17 Dec 2010 19:14:27 +0100: (...) > > The Label widget in fact REPLACES the canvas in the display > rather than being packed within it. I don't know why (try commenting out > the d.pack() line) and see the difference.) > I changed your example a bit, and so we can see that actually the canvas is resized: from Tkinter import * root = Tk() root.geometry('500x500') c=Canvas(root, bg="red", width=400, height=400, relief='solid', bd=4) c.pack() d=Label(c, text="Hello", relief='sunken', bd=2) d.pack() c.update_idletasks() print c.winfo_height(), c.winfo_width() root.mainloop() You can avoid this by ading a c.pack_propagate(0) before packing the label. However I agree, it's better to use create_window() to avoid pitfalls like this. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. To live is always desirable. -- Eleen the Capellan, "Friday's Child", stardate 3498.9 From python at bdurham.com Fri Dec 17 21:57:29 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 15:57:29 -0500 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: References: <1292608339.1589.1410876097@webmail.messagingengine.com> Message-ID: <1292619449.28429.1410902795@webmail.messagingengine.com> Hi Mick, > I have never heard of packing widgets within a canvas. Here's the link that gave me that impression: http://stackoverflow.com/questions/4080413/python-tkinter-place-a-widget-in-a-canvas-widget You can easily add widgets to a canvas just like you do any other container, using pack or grid or place. when you do this, the items will not scroll when you scroll the canvas because they aren't actually part of the canvas. The other choice is to create window objects on the canvas. You do this with the create_window method of the canvas. The advantage is, this window becomes part of the canvas and will scroll along with any other objects on the canvas. The downside is, your only option is absolute placement and you have to explicitly control the size of the widgets. BUT: In reviewing the documentation on this page, I see that there are no pack and grid methods for the Canvas widget: http://effbot.org/tkinterbook/canvas.htm > Just use create_window, so there is no automatic placement, you need to handle all placement. OK. This makes sense. Does the following advice make sense: The only time one should use a Canvas for a general purpose widget container is when they need a container that scrolls. To use a scrollable container one must be prepared to manually position all widgets using the create_window() method call. > Note with the following, packing a label within a canvas ... the Label widget in fact REPLACES the canvas in the display rather than being packed within it. I don't know why (try commenting out the d.pack() line) and see the difference). Interesting example. And I think this makes sense given the fact that Canvas's don't support pack and grid layouts. Thanks for your thoughts, Malcolm From python at bdurham.com Fri Dec 17 22:07:48 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 17 Dec 2010 16:07:48 -0500 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: <20101217215308.e4dd7ccc.klappnase@web.de> References: <1292608339.1589.1410876097@webmail.messagingengine.com> <20101217215308.e4dd7ccc.klappnase@web.de> Message-ID: <1292620068.31850.1410907791@webmail.messagingengine.com> Michael, > However I agree, it's better to use create_window() to avoid pitfalls like this. 1. So the proper way to use Canvases as containers for traditional widgets is to manually handle layout and place all widgets via the create_window() method. 2. The only reason to use a Canvas as a container for traditional widgets is when you need a scrollable container. Are those points accurate? Thanks, Malcolm From klappnase at web.de Fri Dec 17 22:30:44 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 17 Dec 2010 22:30:44 +0100 Subject: [Tkinter-discuss] lambda function to simplify In-Reply-To: <1292609782.5645.7.camel@cristian-desktop> References: <1292609782.5645.7.camel@cristian-desktop> Message-ID: <20101217223044.f2449110.klappnase@web.de> Hi, Thus spoketh craf unto us on Fri, 17 Dec 2010 15:16:22 -0300: (...) > I have access to the function (greeting) from the button and the window > close button. > > It works fine, but wanted to know whether the use of lambda (lambda), > can be expressed in another way more elegant and less confusing. > If I understand you correctly, your problem is that the event callback receives the event instance as argument but the wm_protocol() doesn't? You can circumvent this by defining a default value for the event parameter, as in: class App: def __init__(self, master): self.root = master self.b1 = Tkinter.Button(master) self.b1.pack() self.b1.bind('', self.foo) self.root.protocol('WM_DELETE_WINDOW', self.foo) def foo(self, event=None): greeting(self) In most cases it is probably even better (and less confusing) to avoid calling externally defined functions whereever possible and define prefer class methods instead, as in: class App: def __init__(self, master): self.root = master self.b1 = Tkinter.Button(master) self.b1.pack() self.b1.bind('', self.foo) self.root.protocol('WM_DELETE_WINDOW', self.foo) def foo(self, event=None): self.root.destroy() BTW, I am not sure if you are aware of this, root.destroy() is already defined as default callback for WM_DELETE_WINDOW in Tkinter.py, so it's kind of redundant here; although it won't make much difference in most situations, some people say the canonical way ending a Tkinter app is to end the mainloop with root.quit() instead and destroy() the window after the mainloop ended, as in: root = Tk() root.protocol('WM_DELETE_WINDOW', root.quit) (...)# a lot of code here root.mainloop() root.destroy() That's what they do in IDLE, for example. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Without facts, the decision cannot be made logically. You must rely on your human intuition. -- Spock, "Assignment: Earth", stardate unknown From prog at vtr.net Fri Dec 17 23:15:39 2010 From: prog at vtr.net (craf) Date: Fri, 17 Dec 2010 19:15:39 -0300 Subject: [Tkinter-discuss] [Fwd: Re: lambda function to simplify] Message-ID: <1292624139.10157.5.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael Lange > Para: tkinter-discuss at python.org > Asunto: Re: [Tkinter-discuss] lambda function to simplify > Fecha: Fri, 17 Dec 2010 22:30:44 +0100 > > Hi, > > Thus spoketh craf > unto us on Fri, 17 Dec 2010 15:16:22 -0300: > > (...) > > I have access to the function (greeting) from the button and the window > > close button. > > > > It works fine, but wanted to know whether the use of lambda (lambda), > > can be expressed in another way more elegant and less confusing. > > > > If I understand you correctly, your problem is that the event callback > receives the event instance as argument but the wm_protocol() doesn't? > You can circumvent this by defining a default value for the event > parameter, as in: > > class App: > def __init__(self, master): > self.root = master > self.b1 = Tkinter.Button(master) > self.b1.pack() > self.b1.bind('', self.foo) > self.root.protocol('WM_DELETE_WINDOW', self.foo) > > def foo(self, event=None): > greeting(self) > > In most cases it is probably even better (and less confusing) to avoid > calling externally defined functions whereever possible and define prefer > class methods instead, as in: > > class App: > def __init__(self, master): > self.root = master > self.b1 = Tkinter.Button(master) > self.b1.pack() > self.b1.bind('', self.foo) > self.root.protocol('WM_DELETE_WINDOW', self.foo) > > def foo(self, event=None): > self.root.destroy() > > BTW, I am not sure if you are aware of this, root.destroy() is already > defined as default callback for WM_DELETE_WINDOW in Tkinter.py, so it's > kind of redundant here; although it won't make much difference in most > situations, some people say the canonical way ending a Tkinter app is to > end the mainloop with root.quit() instead and destroy() the window > after the mainloop ended, as in: > > root = Tk() > root.protocol('WM_DELETE_WINDOW', root.quit) > (...)# a lot of code here > root.mainloop() > root.destroy() > > That's what they do in IDLE, for example. > > Regards > > Michael > > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Without facts, the decision cannot be made logically. You must rely on > your human intuition. > -- Spock, "Assignment: Earth", stardate unknown > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss Hi Michael. Sorry, I do not explain well what I wanted ;=) My guess is that if the instruction... self.root.protocol('WM_DELETE_WINDOW', lambda:((lambda e,widget=self:greeting(widget))(self.root))) can be shortened to occupy the same line? It's for a better understanding of the code. Regards Cristian Abarz?a From prog at vtr.net Fri Dec 17 23:49:58 2010 From: prog at vtr.net (craf) Date: Fri, 17 Dec 2010 19:49:58 -0300 Subject: [Tkinter-discuss] Upload control parameter sashpos to load the program. Message-ID: <1292626198.10157.12.camel@cristian-desktop> Hi. I'm trying that opening the window, the position of the handle, is located where you want, using the method "sashpos", in the following code.... -------------------------------------------------------------------- from tkinter import * from tkinter import ttk class App: def __init__(self, master): self.root = master self.paned = ttk.Panedwindow(self.root, orient=HORIZONTAL) self.paned.pack(fill=BOTH, expand=YES) self.f1 = ttk.Labelframe(self.paned, text='One') self.f2 = ttk.Labelframe(self.paned, text='Two') self.paned.add(self.f1) self.paned.add(self.f2) self.paned.sashpos(0,100) <---Here master = Tk() master.geometry('400x400') app = App(master) master.mainloop() -------------------------------------------------------------------- The problem is that the method is not taken into account when loading the window. There is an event that allows to open the program, run the method?. Regards Cristian Abarzua. UBUNTU 9.10 - Tkinter.ttk 8.5 - Python 3.1.1 From klappnase at web.de Sat Dec 18 02:41:57 2010 From: klappnase at web.de (Michael Lange) Date: Sat, 18 Dec 2010 02:41:57 +0100 Subject: [Tkinter-discuss] Upload control parameter sashpos to load the program. In-Reply-To: <1292626198.10157.12.camel@cristian-desktop> References: <1292626198.10157.12.camel@cristian-desktop> Message-ID: <20101218024157.b708187f.klappnase@web.de> Hi, Thus spoketh craf unto us on Fri, 17 Dec 2010 19:49:58 -0300: > Hi. > > I'm trying that opening the window, the position of the handle, is > located where you want, using the method "sashpos", in the following > code.... (...) > -------------------------------------------------------------------- > The problem is that the method is not taken into account when loading > the window. > > There is an event that allows to open the program, run the method?. Try to call update_idletasks() before calling sashpos(), so tk can calculate the size of the widgets first. I haven't tried it right now, but this is usually the first attempt in such cases and will probably help ;) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Superior ability breeds superior ambition. -- Spock, "Space Seed", stardate 3141.9 From prog at vtr.net Sat Dec 18 02:51:47 2010 From: prog at vtr.net (craf) Date: Fri, 17 Dec 2010 22:51:47 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Upload control parameter sashpos to load the program.] Message-ID: <1292637107.2167.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael Lange > Para: tkinter-discuss at python.org > Asunto: Re: [Tkinter-discuss] Upload control parameter sashpos to load > the program. > Fecha: Sat, 18 Dec 2010 02:41:57 +0100 > > Hi, > > Thus spoketh craf > unto us on Fri, 17 Dec 2010 19:49:58 -0300: > > > Hi. > > > > I'm trying that opening the window, the position of the handle, is > > located where you want, using the method "sashpos", in the following > > code.... > (...) > > -------------------------------------------------------------------- > > The problem is that the method is not taken into account when loading > > the window. > > > > There is an event that allows to open the program, run the method?. > > Try to call update_idletasks() before calling sashpos(), so tk can > calculate the size of the widgets first. I haven't tried it right now, > but this is usually the first attempt in such cases and will probably > help ;) > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Superior ability breeds superior ambition. > -- Spock, "Space Seed", stardate 3141.9 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss Hi Michael. This method was that I need!. Thank you very much!. Regards Cristian Abarzua From klappnase at web.de Sat Dec 18 02:53:06 2010 From: klappnase at web.de (Michael Lange) Date: Sat, 18 Dec 2010 02:53:06 +0100 Subject: [Tkinter-discuss] [Fwd: Re: lambda function to simplify] In-Reply-To: <1292624139.10157.5.camel@cristian-desktop> References: <1292624139.10157.5.camel@cristian-desktop> Message-ID: <20101218025306.301d3a07.klappnase@web.de> Hi, Thus spoketh craf unto us on Fri, 17 Dec 2010 19:15:39 -0300: (...) > My guess is that if the instruction... > > self.root.protocol('WM_DELETE_WINDOW', lambda:((lambda > e,widget=self:greeting(widget))(self.root))) > > can be shortened to occupy the same line? > > It's for a better understanding of the code. Oh yes, I misunderstood you. And yes, this line looks a little like a candidate for one of those obfuscated python contests ;) In fact right now I stare at it and I'm quite amazed that it works at all :) (maybe I should mention that it's 3 a.m. here). I think self.root.protocol('WM_DELETE_WINDOW', lambda : greeting(self)) should do the trick, too. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Captain's Log, star date 21:34.5... From prog at vtr.net Sat Dec 18 03:07:59 2010 From: prog at vtr.net (craf) Date: Fri, 17 Dec 2010 23:07:59 -0300 Subject: [Tkinter-discuss] Off Topic : Tkinter in everyday life Message-ID: <1292638079.2167.12.camel@cristian-desktop> Hi everyone.! I apologize in advance, since English is not my native language and some things can not understand and misinterpret. Very recently I found Python and Tkinter. Needless to say, I find a tool Tkinter extremely cool and functional, which I am discovering little by little every day. One question that comes to me, is why very few people work with this tool? Anyone know of companies that use in their development.? Does anyone know which projects or developmental pathway of Tkinter.? Well, I hope not to be taken the wrong way my questions and happy weekend to all! Regards. Cristian Abarzua From klappnase at web.de Sat Dec 18 14:08:58 2010 From: klappnase at web.de (Michael Lange) Date: Sat, 18 Dec 2010 14:08:58 +0100 Subject: [Tkinter-discuss] Off Topic : Tkinter in everyday life In-Reply-To: <1292638079.2167.12.camel@cristian-desktop> References: <1292638079.2167.12.camel@cristian-desktop> Message-ID: <20101218140858.07550215.klappnase@web.de> Hi, Thus spoketh craf unto us on Fri, 17 Dec 2010 23:07:59 -0300: > Hi everyone.! > > I apologize in advance, since English is not my native language and > some things can not understand and misinterpret. > > Very recently I found Python and Tkinter. Needless to say, I find a tool > Tkinter extremely cool and functional, which I am discovering little by > little every day. > > One question that comes to me, is why very few people work with this > tool? > I guess that many people miss features like drag'n'drop, pixmaps themes and so on. I know that a lot of people used to complain about Tk's look and feel and, compared to other toolkits, poor set of core widgets, which however has been greatly improved with ttk in the core. > Anyone know of companies that use in their development.? At least one famous "company" uses Tkinter: http://dsnra.jpl.nasa.gov/software/Python/ http://articles.techrepublic.com.com/5100-10878_11-1045764.html I guess that Tkinter has its place where reliability, stability and quick coding count rather than on our home-pc's desktops, where eye-candy rules :) > > Does anyone know which projects or developmental pathway of Tkinter.? > > Well, I hope not to be taken the wrong way my questions and happy > weekend to all! > The same to you! Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. One of the advantages of being a captain is being able to ask for advice without necessarily having to take it. -- Kirk, "Dagger of the Mind", stardate 2715.2 From python at bdurham.com Sat Dec 18 14:57:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 18 Dec 2010 08:57:44 -0500 Subject: [Tkinter-discuss] Off Topic : Tkinter in everyday life In-Reply-To: <20101218140858.07550215.klappnase@web.de> References: <1292638079.2167.12.camel@cristian-desktop> <20101218140858.07550215.klappnase@web.de> Message-ID: <1292680664.7201.1410984977@webmail.messagingengine.com> Craf, > I find a tool Tkinter extremely cool and functional, which I am discovering little by little every day. Same here!!! I share your enthusiasm for this tool and I'm on a similar path of discovery (hence all my posts on this mailing list). BTW: Another good resource for Tkinter help and code snippets is stackoverflow.com. Search on 'tkinter' or 'ttk'. > One question that comes to me, is why very few people work with this tool? My impression is that many, many, many more people use Tkinter than post on this mailing list :) I've read where Guido (inventor of Python) has stated that Tkinter is by far the most popular GUI framework for Python and the number of Tkinter developers could number in the hundreds of thousands. With support for tile (ttk) now available in Python 2.7 and 3.1, I believe Tkinter is on par with its "competitors" in the Python GUI framework world such as wxPython, pyQt, and pyGUI. Sure, these other frameworks may have more widgets, but how many of these extra widgets are required (or actually get used) in real business applications (even applications where eye candy is preferred)? I believe that most of eye candy requirements can be met with standard ttk (and tk) widgets, high quality icon sets, and reasonable choices for colors, fonts, and padding. In addition to the benefits mentioned by Michael Lange (reliability, stability and quick coding), I would also add ease of deployment as a (business) critical benefit. Tkinter is bundled with all common Python distributions, so its a deployment detail one doesn't need to worry about. Tkinter apps can also be easily "frozen" (at least under Windows where my experience lies). Alternative Python GUI frameworks are often quite difficult to deploy, add significantly to the deployment footprint of an application, and are a major source of support issues. Another benefit of Tkinter vs. other GUI frameworks is that Tkinter is the only GUI framework available for Python 3.x. (also available in 32 and 64 bit versions). > Anyone know of companies that use in their development. AwarePro.com (a startup where I work). Malcolm From python at bdurham.com Sat Dec 18 15:26:43 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 18 Dec 2010 09:26:43 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? Message-ID: <1292682403.12570.1410987145@webmail.messagingengine.com> This post was inspired by Craf's recent post on "Tkinter in everyday life". I'm a recent and enthusiastic convert to Tkinter after having rejected this toolkit for many years. After digging into Tkinter and through the very generous help on this mailing list and elsewhere (stackoverflow.com), I've found that most things that I thought Tkinter couldn't do are actually very doable. Perhaps if we share our Tkinter concerns and doubts, we can all brainstorm ways to fill in missing pieces. Here's my short list of Tkinter weaknesses that I've struggled with: 1. Drag and drop. In fairness, there's a Tkdnd library and a bunch of sample code on the internet. I haven't studied the examples I've collected enough to figure out a simple, reusable way to do this. (Most of my use cases are simply finding a way for users to re-arrange a row of widgets packed or grided into a container) 2. Ability to dynamically stretch and image in real-time. What I would like to do is create widgets with a gradient background where the background image stretches as the widget itself is resized. 3. Creating scrolling containers (I've been spoiled with Tkinter's automatic layouts and don't look forward to manually placing widgets). 4. A way to show an auto-complete popup when one types in a Text widget. There's an example of how to do this in the IDLE source code, I just haven't looked for it yet. As you can see, most of these limitations are limitations of my own learning curve and not limitations of Tkinter itself. Malcolm From michael.odonnell at uam.es Sat Dec 18 18:47:15 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sat, 18 Dec 2010 18:47:15 +0100 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: <1292620068.31850.1410907791@webmail.messagingengine.com> References: <1292608339.1589.1410876097@webmail.messagingengine.com> <20101217215308.e4dd7ccc.klappnase@web.de> <1292620068.31850.1410907791@webmail.messagingengine.com> Message-ID: Hi Malcom, I use both Canvas and Text for scrollable containers. I use the Canvas when I want pixel accurate placement. I use a Text widget for more lazy placement (one can place items after each other on a row, and start a new row with a "\n"). One can make spreadsheets by placing rows of entry widgets of equal width. However, with hundreds of widgets in a text widget, I find performance suffers. Mick On Fri, Dec 17, 2010 at 10:07 PM, wrote: > Michael, > >> However I agree, it's better to use create_window() to avoid pitfalls like this. > > 1. So the proper way to use Canvases as containers for traditional > widgets is to manually handle layout and place all widgets via the > create_window() method. > > 2. The only reason to use a Canvas as a container for traditional > widgets is when you need a scrollable container. > > Are those points accurate? > > Thanks, > Malcolm > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From michael.odonnell at uam.es Sat Dec 18 18:53:01 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sat, 18 Dec 2010 18:53:01 +0100 Subject: [Tkinter-discuss] [Fwd: Re: lambda function to simplify] In-Reply-To: <20101218025306.301d3a07.klappnase@web.de> References: <1292624139.10157.5.camel@cristian-desktop> <20101218025306.301d3a07.klappnase@web.de> Message-ID: Hi Michael, > ? ?self.root.protocol('WM_DELETE_WINDOW', lambda : greeting(self)) I've had trouble with lambdas, because variables are not resolved at declaration time, but at execution time. WOuld not the following be better: self.root.protocol('WM_DELETE_WINDOW', lambda w=self : greeting(w)) ....too tired to actually test your code. Mick On Sat, Dec 18, 2010 at 2:53 AM, Michael Lange wrote: > Hi, > > Thus spoketh craf > unto us on Fri, 17 Dec 2010 19:15:39 -0300: > > > (...) >> My guess is that if the instruction... >> >> self.root.protocol('WM_DELETE_WINDOW', lambda:((lambda >> e,widget=self:greeting(widget))(self.root))) >> >> can be shortened to occupy the same line? >> >> It's for a better understanding of the code. > > Oh yes, I misunderstood you. > And yes, this line looks a little like a candidate for one of those > obfuscated python contests ;) In fact right now I stare at it and I'm > quite amazed that it works at all :) (maybe I should mention that it's 3 > a.m. here). > I think > > > should do the trick, too. > > Regards > > Michael > > > .-.. .. ...- . ? .-.. --- -. --. ? .- -. -.. ? .--. .-. --- ... .--. . .-. > > Captain's Log, star date 21:34.5... > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From klappnase at web.de Sat Dec 18 19:15:40 2010 From: klappnase at web.de (Michael Lange) Date: Sat, 18 Dec 2010 19:15:40 +0100 Subject: [Tkinter-discuss] [Fwd: Re: lambda function to simplify] In-Reply-To: References: <1292624139.10157.5.camel@cristian-desktop> <20101218025306.301d3a07.klappnase@web.de> Message-ID: <20101218191540.02e2b225.klappnase@web.de> Hi, Thus spoketh "Michael O'Donnell" unto us on Sat, 18 Dec 2010 18:53:01 +0100: > Hi Michael, > > > ? ?self.root.protocol('WM_DELETE_WINDOW', lambda : greeting(self)) > > I've had trouble with lambdas, because variables are not resolved > at declaration time, but at execution time. WOuld not the following be > better: > > self.root.protocol('WM_DELETE_WINDOW', lambda w=self : greeting(w)) > > ....too tired to actually test your code. I don't like lambdas too much either :) In this case both variants will work, still I'd prefer to wrap the lambbda into a class method, but that's just a matter of taste. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. The heart is not a logical organ. -- Dr. Janet Wallace, "The Deadly Years", stardate 3479.4 From kw at codebykevin.com Sun Dec 19 06:03:27 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 19 Dec 2010 00:03:27 -0500 Subject: [Tkinter-discuss] Off Topic : Tkinter in everyday life In-Reply-To: <1292680664.7201.1410984977@webmail.messagingengine.com> References: <1292638079.2167.12.camel@cristian-desktop> <20101218140858.07550215.klappnase@web.de> <1292680664.7201.1410984977@webmail.messagingengine.com> Message-ID: <4D0D921F.4000006@codebykevin.com> On 12/18/10 8:57 AM, python at bdurham.com wrote: > Craf, > >> I find a tool Tkinter extremely cool and functional, which I am discovering little by little every day. > > Same here!!! I share your enthusiasm for this tool and I'm on a similar > path of discovery (hence all my posts on this mailing list). BTW: > Another good resource for Tkinter help and code snippets is > stackoverflow.com. Search on 'tkinter' or 'ttk'. Agreed. I am a big advocate of Tkinter (and Tk). > >> One question that comes to me, is why very few people work with this tool? I think there's still a perception that Tkinter is ugly and outdated, and advocates of other toolkits are quite loud in attacking Tkinter, for whatever reason. Tkinter developers, on the other hand, just tend to go about their work. See Frederick Lundh, for instance. > > My impression is that many, many, many more people use Tkinter than post > on this mailing list :) Also true. > > I've read where Guido (inventor of Python) has stated that Tkinter is by > far the most popular GUI framework for Python and the number of Tkinter > developers could number in the hundreds of thousands. Tkinter was the first toolkit for Python, and hence the one that got installed. Back in the 1990s Tk was a revolutionary way to create GUI's for its simplicity and power. Compared to the other systems at the time, such as Motif, it was orders of magnitude easier and faster. > > With support for tile (ttk) now available in Python 2.7 and 3.1, I > believe Tkinter is on par with its "competitors" in the Python GUI > framework world such as wxPython, pyQt, and pyGUI. Sure, these other > frameworks may have more widgets, but how many of these extra widgets > are required (or actually get used) in real business applications (even > applications where eye candy is preferred)? In general, I'd say you're right. > > I believe that most of eye candy requirements can be met with standard > ttk (and tk) widgets, high quality icon sets, and reasonable choices for > colors, fonts, and padding. Yup. > > In addition to the benefits mentioned by Michael Lange (reliability, > stability and quick coding), I would also add ease of deployment as a > (business) critical benefit. Tkinter is bundled with all common Python > distributions, so its a deployment detail one doesn't need to worry > about. Tkinter apps can also be easily "frozen" (at least under Windows > where my experience lies). Alternative Python GUI frameworks are often > quite difficult to deploy, add significantly to the deployment footprint > of an application, and are a major source of support issues. wxPython and PyQt are (reportedly) both pretty easy to install and/or freeze on Windows, but I might be wrong here. > > >> Anyone know of companies that use in their development. > > AwarePro.com (a startup where I work). See my website for another example. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From kw at codebykevin.com Sun Dec 19 05:55:21 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 18 Dec 2010 23:55:21 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <1292682403.12570.1410987145@webmail.messagingengine.com> References: <1292682403.12570.1410987145@webmail.messagingengine.com> Message-ID: <4D0D9039.5080408@codebykevin.com> On 12/18/10 9:26 AM, python at bdurham.com wrote: > > Here's my short list of Tkinter weaknesses that I've struggled with: > > 1. Drag and drop. In fairness, there's a Tkdnd library and a bunch of > sample code on the internet. I haven't studied the examples I've > collected enough to figure out a simple, reusable way to do this. (Most > of my use cases are simply finding a way for users to re-arrange a row > of widgets packed or grided into a container) The cross-platform binary TkDND extension by George Petasis (ably wrapped for Python by Michael Lange) is an obvious choice here, but Tkinter also has its own built-in tkdnd module, based on the canvas widget, which is useful for simple things. It's not used much as far as I can tell, but here is some documentation for it. http://www.bitflipper.ca/Documentation/Tkdnd.html > > 2. Ability to dynamically stretch and image in real-time. What I would > like to do is create widgets with a gradient background where the > background image stretches as the widget itself is resized. PIL might help with this, I don't know. > > 3. Creating scrolling containers (I've been spoiled with Tkinter's > automatic layouts and don't look forward to manually placing widgets). Doesn't PMW have some sort of scrolling widget container? > > 4. A way to show an auto-complete popup when one types in a Text widget. > There's an example of how to do this in the IDLE source code, I just > haven't looked for it yet. Yes, you can probably look at IDLE as a good source for this. My gripes with Tk: 1. Lack of a cross-platform printing solution. Every other cross-platform toolkit does this, but no one has done it for Tk. 2. Lack of a modern HTML widget or an easy-to-use, cross-platform way of wrapping one of the major browser platforms (Gecko, Webkit, IE). Lots of partial solutions, but nothing that abstracts the platform differences and presents a single API. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From klappnase at web.de Sun Dec 19 16:58:51 2010 From: klappnase at web.de (Michael Lange) Date: Sun, 19 Dec 2010 16:58:51 +0100 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <1292682403.12570.1410987145@webmail.messagingengine.com> References: <1292682403.12570.1410987145@webmail.messagingengine.com> Message-ID: <20101219165851.06defb8f.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Sat, 18 Dec 2010 09:26:43 -0500: > This post was inspired by Craf's recent post on "Tkinter in everyday > life". > > I'm a recent and enthusiastic convert to Tkinter after having rejected > this toolkit for many years. > > After digging into Tkinter and through the very generous help on this > mailing list and elsewhere (stackoverflow.com), I've found that most > things that I thought Tkinter couldn't do are actually very doable. > Perhaps if we share our Tkinter concerns and doubts, we can all > brainstorm ways to fill in missing pieces. > > Here's my short list of Tkinter weaknesses that I've struggled with: > > 1. Drag and drop. In fairness, there's a Tkdnd library and a bunch of > sample code on the internet. I haven't studied the examples I've > collected enough to figure out a simple, reusable way to do this. (Most > of my use cases are simply finding a way for users to re-arrange a row > of widgets packed or grided into a container) I agree with this; as Kevin Walzer already pointed out, the Tkdnd module is nice for DnD within your application, but for "real" DnD you need George Petasis tkdnd library, which unforunately supports only drops on unix. In fact there used to be an earlier version of this tkdnd library, where drag *and* drop worked on unix, which unfortunately is not being maintained any longer. > > 2. Ability to dynamically stretch and image in real-time. What I would > like to do is create widgets with a gradient background where the > background image stretches as the widget itself is resized. > > 3. Creating scrolling containers (I've been spoiled with Tkinter's > automatic layouts and don't look forward to manually placing widgets). If you don't need a themed one, you can use the Pmw.ScrolledFrame or the Tix.ScrolledWidget, which is included in the standard library and even easier to use than its Pmw counterpart (we've had this topic earlier here, I admit that I totally forgot about Tix :), see this small example: from Tix import * r = Tk() r.geometry('800x400') sw = ScrolledWindow(r) sw.pack(fill='both', expand=1) for x in range(30): for y in range(20): Entry(sw.subwidget('window'), bd=0, highlightthickness=1, highlightbackground='gray50').grid(row=x, column=y) r.mainloop() I agree with you though, that it would be nice to have scrolled widgets within standard Tk. A few other things I miss from Tkinter: * support for image formats other than gif * text rotation The Tk-8.6 beta release however adds a -rotate option to the canvas text item and support for png images, so these issues will be resolved soon :) * built-in tooltips were also nice, I'd love to be able to do Button(master, text='foo', tooltip='bar'...) * a decent html widget * on unix some dialogs (file dialog, color chooser...) could be improved Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. A Vulcan can no sooner be disloyal than he can exist without breathing. -- Kirk, "The Menagerie", stardate 3012.4 From python at bdurham.com Sun Dec 19 18:06:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Dec 2010 12:06:47 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <20101219165851.06defb8f.klappnase@web.de> References: <1292682403.12570.1410987145@webmail.messagingengine.com> <20101219165851.06defb8f.klappnase@web.de> Message-ID: <1292778407.32314.1411107233@webmail.messagingengine.com> Michael, > A few other things I miss from Tkinter: > support for image formats other than gif We use PIL which adds about 700K to our Window distributions. My understanding is that PIL is cross platform, available for both the 2.x and 3.x branches of Python and both the 32-bit and 64-bit versions of Python. Are there problems deploying or using PIL for your customers? (We're developing for Windows but hope to port to other platforms in the future) > The Tk-8.6 beta release however adds a -rotate option to the canvas text item and support for png images, so these issues will be resolved soon :) Nice!! (although PIL adds many other useful image capabilities) > built-in tooltips were also nice I highly recommend the following tooltip library. Easily used, many capabilities, beautifully rendered. The only limitation I've found that needs to be addressed is that tooltips are always displayed south east of a widget. This means that a widget aligned on the far right and/or bottom of a user's desktop will not be visible. http://code.activestate.com/recipes/576688/ There's also a simpler tooltip approach here: http://www.voidspace.org.uk/python/weblog/arch_d7_2006_07_01.shtml > a decent html widget Have you looked at Tkhtml? http://www.hwaci.com/sw/tkhtml/ Quote: Tkhtml is a Tcl/Tk widget that displays HTML. Tkhtml is implemented in C. It is a true widget, not a metawidget implemented using the Text or Canvas widgets of the Tcl/Tk core. Tkhtml can be used with Tcl/Tk8.0 or later. The shared libraries use the new stubs mechanism, so you should be able to load Tkhtml with any version of "wish" beginning with 8.0.6. (Not sure what any of this really means). Python wrapper http://tix.sourceforge.net/Tixapps/src/Python/TkHtml.py Its on my todo-list to take a look at this component. Would be curious to hear if anyone is using this widget with Python (especially a Windows based version of Python). > If you don't need a themed one, you can use the Pmw.ScrolledFrame or the Tix.ScrolledWidget, which is included in the standard library and even easier to use than its Pmw counterpart Thanks for the Tix example. Works well, but now that we're using ttk, it does look a bit dated. I guess we're spoiled ;) Malcolm From python at bdurham.com Sun Dec 19 18:23:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Dec 2010 12:23:27 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <4D0D9039.5080408@codebykevin.com> References: <1292682403.12570.1410987145@webmail.messagingengine.com> <4D0D9039.5080408@codebykevin.com> Message-ID: <1292779407.2940.1411109991@webmail.messagingengine.com> Kevin, > My gripes with Tk: > 1. Lack of a cross-platform printing solution. Every other cross-platform toolkit does this, but no one has done it for Tk. We generate RTF (or HTM) files for output instead of trying to battle platform specific printing challenges. One advantage of generating RTF and HTM files is that users get revisable form electronic versions of their output for free. > 2. Lack of a modern HTML widget or an easy-to-use, cross-platform way of wrapping one of the major browser platforms (Gecko, Webkit, IE). Lots of partial solutions, but nothing that abstracts the platform differences and presents a single API. Have you looked at Tkhtml? http://www.hwaci.com/sw/tkhtml/ Quote: Tkhtml is a Tcl/Tk widget that displays HTML. Tkhtml is implemented in C. It is a true widget, not a metawidget implemented using the Text or Canvas widgets of the Tcl/Tk core. Python wrapper http://tix.sourceforge.net/Tixapps/src/Python/TkHtml.py Malcolm From python at bdurham.com Sun Dec 19 18:35:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Dec 2010 12:35:27 -0500 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: References: <1292608339.1589.1410876097@webmail.messagingengine.com><20101217215308.e4dd7ccc.klappnase@web.de><1292620068.31850.1410907791@webmail.messagingengine.com> Message-ID: <1292780127.5452.1411111483@webmail.messagingengine.com> Mick, > I use both Canvas and Text for scrollable containers. > I use the Canvas when I want pixel accurate placement. > > I use a Text widget for more lazy placement (one can place items after each other on a row, and start a new row with a "\n"). One can make spreadsheets by placing rows of entry widgets of equal width. However, with hundreds of widgets in a text widget, I find performance suffers. I love the idea of creating scrollable containers using Text widgets. I'll give this technique a try (with your caution about performance for large number of widgets). Thanks, Malcolm From python at bdurham.com Sun Dec 19 18:40:04 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Dec 2010 12:40:04 -0500 Subject: [Tkinter-discuss] Anyone using Tkinter for mobile device applications? Message-ID: <1292780404.5868.1411111831@webmail.messagingengine.com> Wondering if any of you are using Tkinter for mobile device applications and if so, what has your experience been like (tricks, traps, etc)? By mobile I mean small Linux devices, ipad/iphone, Windows CE or the new mobile Windows 7 Mobile. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Sun Dec 19 18:50:47 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 19 Dec 2010 12:50:47 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <1292779407.2940.1411109991@webmail.messagingengine.com> References: <1292682403.12570.1410987145@webmail.messagingengine.com> <4D0D9039.5080408@codebykevin.com> <1292779407.2940.1411109991@webmail.messagingengine.com> Message-ID: <4D0E45F7.6040601@codebykevin.com> On 12/19/10 12:23 PM, python at bdurham.com wrote: >> 2. Lack of a modern HTML widget or an easy-to-use, cross-platform way of wrapping one of the major browser platforms (Gecko, Webkit, IE). Lots of partial solutions, but nothing that abstracts the platform differences and presents a single API. > > Have you looked at Tkhtml? > http://www.hwaci.com/sw/tkhtml/ > > Quote: Tkhtml is a Tcl/Tk widget that displays HTML. Tkhtml is > implemented in C. It is a true widget, not a metawidget implemented > using the Text or Canvas widgets of the Tcl/Tk core. > > Python wrapper > http://tix.sourceforge.net/Tixapps/src/Python/TkHtml.py I've used TkHTML in several of my applications. It's fine if all you need is basic HTML--i.e. HTML 3.2. It hasn't been updated in several years, and so doesn't support more modern HTML features like CSS. Its display is rather ugly. There was an ambitious attempt to update it, called TkHTML 3, but the project's developer and sponsor moved on to other projects, and now it's just in an alpha, unmaintained state. Since I'm a Mac-only developer, I'm investigating the possibility of simply embedding a Cocoa WebKit view inside a Tk widget and using that in my apps. This can be done on Windows using IE and the OpTcl extension. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From kw at codebykevin.com Sun Dec 19 18:52:34 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 19 Dec 2010 12:52:34 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <4D0E45F7.6040601@codebykevin.com> References: <1292682403.12570.1410987145@webmail.messagingengine.com> <4D0D9039.5080408@codebykevin.com> <1292779407.2940.1411109991@webmail.messagingengine.com> <4D0E45F7.6040601@codebykevin.com> Message-ID: <4D0E4662.5000604@codebykevin.com> On 12/19/10 12:50 PM, Kevin Walzer wrote: cts, and now it's just in an alpha, unmaintained state. > > Since I'm a Mac-only developer, I'm investigating the possibility of > simply embedding a Cocoa WebKit view inside a Tk widget and using that > in my apps. This can be done on Windows using IE and the OpTcl extension. To clarify: a similar result can be achieved on Windows with IE and OpTcl. Obviously IE's engine is not WebKit. :-) -- Kevin Walzer Code by Kevin http://www.codebykevin.com From klappnase at web.de Sun Dec 19 19:29:23 2010 From: klappnase at web.de (Michael Lange) Date: Sun, 19 Dec 2010 19:29:23 +0100 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <1292778407.32314.1411107233@webmail.messagingengine.com> References: <1292682403.12570.1410987145@webmail.messagingengine.com> <20101219165851.06defb8f.klappnase@web.de> <1292778407.32314.1411107233@webmail.messagingengine.com> Message-ID: <20101219192923.8bc1d28e.klappnase@web.de> Thus spoketh python at bdurham.com unto us on Sun, 19 Dec 2010 12:06:47 -0500: > Michael, > > > A few other things I miss from Tkinter: > > support for image formats other than gif > > We use PIL which adds about 700K to our Window distributions. My > understanding is that PIL is cross platform, available for both the 2.x > and 3.x branches of Python and both the 32-bit and 64-bit versions of > Python. Are there problems deploying or using PIL for your customers? > (We're developing for Windows but hope to port to other platforms in the > future) The problem is that the ImageTk.PhotoImage does not support alpha channels, so some icons won't look so hot ;) (...) > > Thanks for the Tix example. Works well, but now that we're using ttk, it > does look a bit dated. I guess we're spoiled ;) I made a little copy'n'paste exercise with the Pmw.ScrolledFrame code, so here's a slightly simplified version of a Pmw.ScrolledFrame in pure Tkinter that uses ttk. It seems to work ok (I haven't done much testing though): http://tkinter.unpy.net/wiki/ThemedScrolledFrame Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You're too beautiful to ignore. Too much woman. -- Kirk to Yeoman Rand, "The Enemy Within", stardate unknown From michael.odonnell at uam.es Sun Dec 19 19:56:33 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sun, 19 Dec 2010 19:56:33 +0100 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: <1292780127.5452.1411111483@webmail.messagingengine.com> References: <1292608339.1589.1410876097@webmail.messagingengine.com> <20101217215308.e4dd7ccc.klappnase@web.de> <1292620068.31850.1410907791@webmail.messagingengine.com> <1292780127.5452.1411111483@webmail.messagingengine.com> Message-ID: As an example of how to use a Text widget as a container, below is a simple spreadsheet made using Entry widgets organised into a Text widget. The user can edit cells, and later save the values of the cells as a tab delimited file by pressing the "Save" button. from Tkinter import * class ScrolledText(Frame): def __init__(self, master, **keywords): # Set some defaults if not keywords.has_key("width"): keywords["width"]=24 if not keywords.has_key("bg"): keywords["bg"]="white" if not keywords.has_key("relief"): keywords["relief"]="sunken" Frame.__init__(self, master) self.config(bg=keywords["bg"]) # Scrollbars scrollbar = Scrollbar(self, orient=VERTICAL) # Create the Text wgt self.text=Text(self, yscrollcommand=scrollbar.set, **keywords) scrollbar.config(command=self.text.yview) scrollbar.pack(side=RIGHT, fill=Y) self.text.pack(side=LEFT, fill=BOTH, expand=True) self.scroll=scrollbar def saveSpreadsheet(w): out=open("speadsheet.txt", "w") for row in w.rows: out.write("\t".join([col.get() for col in row])+"\n") out.close() tk = Tk() stw = ScrolledText(tk, width=100, height=60, wrap="none") stw.pack(side=BOTTOM, expand=TRUE, fill=BOTH) Button(tk, text="Save Spreadsheet", command=lambda w=stw: saveSpreadsheet(w)).pack(side=TOP) stw.rows=[] for row in range(60): cols=[] for col in range(20): x=Entry(stw.text, width=10) x.row=row x.col=col cols.append(x) stw.text.window_create(END, window=x) stw.text.insert(END, "\n") stw.rows.append(cols) tk.mainloop() On Sun, Dec 19, 2010 at 6:35 PM, wrote: > Mick, > >> I use both Canvas and Text for scrollable containers. >> I use the Canvas when I want pixel accurate placement. >> >> I use a Text widget for more lazy placement (one can place items after each other on a row, and start a new row with a "\n"). One can make spreadsheets by placing rows of entry widgets of equal width. However, with hundreds of widgets in a text widget, I find performance suffers. > > I love the idea of creating scrollable containers using Text widgets. > I'll give this technique a try (with your caution about performance for > large number of widgets). > > Thanks, > Malcolm > From python at bdurham.com Mon Dec 20 00:12:10 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Dec 2010 18:12:10 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <4D0E4662.5000604@codebykevin.com> References: <1292682403.12570.1410987145@webmail.messagingengine.com> <4D0D9039.5080408@codebykevin.com> <1292779407.2940.1411109991@webmail.messagingengine.com><4D0E45F7.6040601@codebykevin.com> <4D0E4662.5000604@codebykevin.com> Message-ID: <1292800330.6374.1411144953@webmail.messagingengine.com> Kevin, > A similar result can be achieved on Windows with IE and OpTcl. Thanks for this tip. Anyone else doing something with this type of browser/Tkinter integration under Windows? Malcolm From python at bdurham.com Mon Dec 20 00:27:50 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Dec 2010 18:27:50 -0500 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: References: <1292608339.1589.1410876097@webmail.messagingengine.com><20101217215308.e4dd7ccc.klappnase@web.de><1292620068.31850.1410907791@webmail.messagingengine.com><1292780127.5452.1411111483@webmail.messagingengine.com> Message-ID: <1292801270.9083.1411146739@webmail.messagingengine.com> Mick, > As an example of how to use a Text widget as a container, > below is a simple spreadsheet made using Entry widgets organised > into a Text widget. The user can edit cells, and later save the values of > the cells as a tab delimited file by pressing the "Save" button. Cool! Thank you for sharing that example. Malcolm From python at bdurham.com Mon Dec 20 00:30:04 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 19 Dec 2010 18:30:04 -0500 Subject: [Tkinter-discuss] What do you feel is missing from Tkinter? In-Reply-To: <20101219192923.8bc1d28e.klappnase@web.de> References: <1292682403.12570.1410987145@webmail.messagingengine.com><20101219165851.06defb8f.klappnase@web.de><1292778407.32314.1411107233@webmail.messagingengine.com> <20101219192923.8bc1d28e.klappnase@web.de> Message-ID: <1292801404.9311.1411146123@webmail.messagingengine.com> Michael, > The problem is that the ImageTk.PhotoImage does not support alpha channels, so some icons won't look so hot ;) Damn! I hadn't noticed that limitation :( > I made a little copy'n'paste exercise with the Pmw.ScrolledFrame code, so > here's a slightly simplified version of a Pmw.ScrolledFrame in pure > Tkinter that uses ttk. It seems to work ok (I haven't done much testing > though): > > http://tkinter.unpy.net/wiki/ThemedScrolledFrame Hey, cool! Thanks for sharing that example. Looks great on my end (Python 2.7 running under Windows 7). Malcolm From prog at vtr.net Mon Dec 20 13:38:32 2010 From: prog at vtr.net (craf) Date: Mon, 20 Dec 2010 09:38:32 -0300 Subject: [Tkinter-discuss] [Fwd: Off Topic : Tkinter in everyday life] Message-ID: <1292848712.2410.7.camel@cristian-desktop> Hi. I want to thank everyone for the excellent feedback to my questions. I think we all share the view that Tkinter is a rough diamond. Through all the examples that have selflessly shared, I can see that their limitations are given only by the limits of our imagination. it has been refreshing to find a forum where the level of the questions does not matter. Thank, really. Regards Cristian Abarz?a. From Vasilis.Vlachoudis at cern.ch Mon Dec 20 15:05:33 2010 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Mon, 20 Dec 2010 14:05:33 +0000 Subject: [Tkinter-discuss] (no subject) Message-ID: <0BC70B5D93E054469872FFD0FE07220E042B14@PLOXCHG13.cern.ch> Dear all, the default behavior of the Entry/Text on how they react to Cut&Paste is a bit problematic (at least on linux) Imaging that the entry contains the text "foobar" with the first 3 letters "foo" highlighted and we have the word "test" copied previously on the clipboard. When we press Ctrl-V to paste the clipboard text "test", tk will not delete the "foo" before inserting the "test" and we will get the text "footestbar" with the "foo" still highlighted. (The "test" will be inserted at the location of the cursor) Normally what the user will expect will be to delete first the "foo" and then insert the "test" getting the string "testbar" with the "test" highlighted. Do you know how I can change the behavior without the need to override the default Entry class and substitute it in the whole project? Vasilis Vlachoudis Dep EN, CERN CH-1211 GENEVA 23 SWITZERLAND Phone: +41-22 767 9851 GSM: +41-76 487 4378 Fax: +41-22 766 9644 -------------- next part -------------- An HTML attachment was scrubbed... URL: From prog at vtr.net Mon Dec 20 15:36:58 2010 From: prog at vtr.net (craf) Date: Mon, 20 Dec 2010 11:36:58 -0300 Subject: [Tkinter-discuss] [Fwd: Anyone using Tkinter for mobile device applications?] Message-ID: <1292855818.6580.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: python at bdurham.com > Para: Python-Tkinter > Asunto: [Tkinter-discuss] Anyone using Tkinter for mobile device > applications? > Fecha: Sun, 19 Dec 2010 12:40:04 -0500 > > Wondering if any of you are using Tkinter for mobile device > applications and if so, what has your experience been like (tricks, > traps, etc)? > > By mobile I mean small Linux devices, ipad/iphone, Windows CE or the > new mobile Windows 7 Mobile. > > Thanks, > Malcolm > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss Hi Malcom Apparently, python works fine on the Iphone, but Tkinter does not, as it has its own graphics API. I leave you the link. http://bytes.com/topic/python/answers/851129-python-iphone-actually-rather-good Regards. Cristian Abarzua F From prog at vtr.net Mon Dec 20 15:41:11 2010 From: prog at vtr.net (craf) Date: Mon, 20 Dec 2010 11:41:11 -0300 Subject: [Tkinter-discuss] [Fwd: Anyone using Tkinter for mobile device applications?] Message-ID: <1292856071.6580.4.camel@cristian-desktop> > De: python at bdurham.com > Para: Python-Tkinter > Asunto: [Tkinter-discuss] Anyone using Tkinter for mobile device > applications? > Fecha: Sun, 19 Dec 2010 12:40:04 -0500 > > Wondering if any of you are using Tkinter for mobile device > applications and if so, what has your experience been like (tricks, > traps, etc)? > > By mobile I mean small Linux devices, ipad/iphone, Windows CE or the > new mobile Windows 7 Mobile. > > Thanks, > Malcolm I send this address with Tkinter reference to Windows CE: http://pythonce.sourceforge.net/Wikka/HomePage http://pythonce.sourceforge.net/Wikka/Tkinter Regards. Cristian. From python at bdurham.com Mon Dec 20 16:20:10 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 20 Dec 2010 10:20:10 -0500 Subject: [Tkinter-discuss] Anyone using Tkinter for mobile device applications? In-Reply-To: <1292856071.6580.4.camel@cristian-desktop> References: <1292856071.6580.4.camel@cristian-desktop> Message-ID: <1292858410.22942.1411250063@webmail.messagingengine.com> Cristian, Thanks for the links. Malcolm From python at bdurham.com Mon Dec 20 16:30:23 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 20 Dec 2010 10:30:23 -0500 Subject: [Tkinter-discuss] [Fwd: Off Topic : Tkinter in everyday life] In-Reply-To: <1292848712.2410.7.camel@cristian-desktop> References: <1292848712.2410.7.camel@cristian-desktop> Message-ID: <1292859023.26938.1411252167@webmail.messagingengine.com> > I want to thank everyone for the excellent feedback to my questions. I think we all share the view that Tkinter is a rough diamond. > > Through all the examples that have selflessly shared, I can see that their limitations are given only by the limits of our imagination. > > It has been refreshing to find a forum where the level of the questions does not matter. > > Thank, really. +1! Malcolm From python at bdurham.com Mon Dec 20 17:41:11 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 20 Dec 2010 11:41:11 -0500 Subject: [Tkinter-discuss] Techniques for creating tables/grids (was When to use a Canvas vs. a Frame from a container perspective?) In-Reply-To: <20101220162249.GA15692@lairds.us> References: <1292608339.1589.1410876097@webmail.messagingengine.com> <20101217215308.e4dd7ccc.klappnase@web.de> <1292620068.31850.1410907791@webmail.messagingengine.com> <1292780127.5452.1411111483@webmail.messagingengine.com> <20101220162249.GA15692@lairds.us> Message-ID: <1292863271.18034.1411263663@webmail.messagingengine.com> Cameron, . > While many valuable applications have been coded through the years using exactly this cell-in-Text technique, and the code above nicely demonstrates the promised scrolling, those focused on spreadsheet-like constructs will want to know about . What is your opinion on using the new ttk Treeview control to implement multi-cell tables and grids? My understanding is that one can configure the Treeview control as a single level, multi-column list/grid and then float a borderless Toplevel window with an input widget over the current Treeview "cell" to allow for input? Disclaimer: I haven't tried this yet. Malcolm From Cameron at phaseit.net Mon Dec 20 17:22:50 2010 From: Cameron at phaseit.net (Cameron Laird) Date: Mon, 20 Dec 2010 16:22:50 +0000 Subject: [Tkinter-discuss] When to use a Canvas vs. a Frame from a container perspective? In-Reply-To: References: <1292608339.1589.1410876097@webmail.messagingengine.com> <20101217215308.e4dd7ccc.klappnase@web.de> <1292620068.31850.1410907791@webmail.messagingengine.com> <1292780127.5452.1411111483@webmail.messagingengine.com> Message-ID: <20101220162249.GA15692@lairds.us> On Sun, Dec 19, 2010 at 07:56:33PM +0100, Michael O'Donnell wrote: . . . > As an example of how to use a Text widget as a container, > below is a simple spreadsheet made using Entry widgets organised > into a Text widget. The user can edit cells, and later save the values of > the cells as a tab delimited file by pressing the "Save" button. > > from Tkinter import * > > class ScrolledText(Frame): > > def __init__(self, master, **keywords): > > # Set some defaults > if not keywords.has_key("width"): keywords["width"]=24 > if not keywords.has_key("bg"): keywords["bg"]="white" > if not keywords.has_key("relief"): keywords["relief"]="sunken" > > Frame.__init__(self, master) > self.config(bg=keywords["bg"]) > > # Scrollbars > scrollbar = Scrollbar(self, orient=VERTICAL) > > # Create the Text wgt > self.text=Text(self, yscrollcommand=scrollbar.set, **keywords) > scrollbar.config(command=self.text.yview) > > scrollbar.pack(side=RIGHT, fill=Y) > self.text.pack(side=LEFT, fill=BOTH, expand=True) > self.scroll=scrollbar > > def saveSpreadsheet(w): > out=open("speadsheet.txt", "w") > for row in w.rows: > out.write("\t".join([col.get() for col in row])+"\n") > out.close() > > tk = Tk() > stw = ScrolledText(tk, width=100, height=60, wrap="none") > stw.pack(side=BOTTOM, expand=TRUE, fill=BOTH) > Button(tk, text="Save Spreadsheet", command=lambda w=stw: > saveSpreadsheet(w)).pack(side=TOP) > > stw.rows=[] > for row in range(60): > cols=[] > for col in range(20): > x=Entry(stw.text, width=10) > x.row=row > x.col=col > cols.append(x) > stw.text.window_create(END, window=x) > stw.text.insert(END, "\n") > stw.rows.append(cols) > > tk.mainloop() . . . While many valuable applications have been coded through the years using exactly this cell-in-Text technique, and the code above nicely demonstrates the promised scrolling, those focused on spreadsheet-like constructs will want to know about . From klappnase at web.de Mon Dec 20 18:12:09 2010 From: klappnase at web.de (Michael Lange) Date: Mon, 20 Dec 2010 18:12:09 +0100 Subject: [Tkinter-discuss] (no subject) In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E042B14@PLOXCHG13.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E042B14@PLOXCHG13.cern.ch> Message-ID: <20101220181209.582f11da.klappnase@web.de> Hi Thus spoketh Vasilis Vlachoudis unto us on Mon, 20 Dec 2010 14:05:33 +0000: > Dear all, > > the default behavior of the Entry/Text on how they react to Cut&Paste > is a bit problematic (at least on linux) Imaging that the entry > contains the text "foobar" with the first 3 letters "foo" highlighted > and we have the word "test" copied previously on the clipboard. When we > press Ctrl-V to paste the clipboard text "test", tk will not delete the > "foo" before inserting the "test" and we will get the text "footestbar" > with the "foo" still highlighted. (The "test" will be inserted at the > location of the cursor) > > Normally what the user will expect will be to delete first the "foo" > and then insert the "test" getting the string "testbar" with the "test" > highlighted. > > Do you know how I can change the behavior without the need to override > the default Entry class and substitute it in the whole project? This behavior is intentional by Tk developers, maybe it matched some old Motif standard, I don't know for sure. The binding is defined in entry.tcl as binding to the virtual <> event: ################################## bind Entry <> { global tcl_platform catch { if {[tk windowingsystem] ne "x11"} { catch { %W delete sel.first sel.last } } %W insert insert [::tk::GetSelection %W CLIPBOARD] tk::EntrySeeInsert %W } } ################################# You see, in the fourth line they omit the deleting of the selection on X11 systems. If you want to change this, you must define a new callback for <> events for the Entry class and use bind_class() to override the default binding. We can use most of the code from the default binding and "translate" it into python, where %W corresponds with the event's widget attribute, and the catch command works much like a try..except in python; the "special" tk commands need to be wrapped in the widget's tk.call() function: ###################################### from Tkinter import * root = Tk() def entry_paste(event): try: event.widget.delete('sel.first', 'sel.last') except TclError: pass# nothing is selected # in tk.call() use the widget's string representation event.widget._w # instead of event.widget, which is the widget instance itself text = event.widget.tk.call('::tk::GetSelection', event.widget._w, 'CLIPBOARD') event.widget.insert('insert', text) event.widget.tk.call('tk::EntrySeeInsert', event.widget._w) root.bind_class('Entry', '<>', entry_paste) # create an Entry to see if it works: Entry(root).pack() root.mainloop() ###################################### I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Vulcans do not approve of violence. -- Spock, "Journey to Babel", stardate 3842.4 From python at bdurham.com Mon Dec 20 18:18:00 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 20 Dec 2010 12:18:00 -0500 Subject: [Tkinter-discuss] Using 3rd party Tk/Tcl libraries with Python/Tkinter Message-ID: <1292865480.30774.1411269615@webmail.messagingengine.com> >From time to time I've seen Tkinter developers reference 3rd party Tk/Tcl libraries. Some examples are the PMW widgets, TkDnd, and TkTable. Here are some questions about these 3rd party components from the perspective of a Python developer new to Tkinter (without any Tk/Tcl experience): 1. Do these 3rd party components require compilation via a C compiler or is there a repository with pre-compiled components for each platform? 2. Are there issues related to what version of Python a developer is using, eg. each release of Python uses a different version of Tk/Tcl? 3. Where do these component's library files get placed on Windows, Linux, and Mac OS's? What I understand so far is that one must find or create Python wrapper code in order to use 3rd party Tk/Tcl libraries. After that I'm stuck ;) BTW: My personal interest is in solutions that work with Python 2.7 for Windows but I thought I'd ask this question in a way that all Python developers might benefit. Thank you, Malcolm From klappnase at web.de Mon Dec 20 18:24:55 2010 From: klappnase at web.de (Michael Lange) Date: Mon, 20 Dec 2010 18:24:55 +0100 Subject: [Tkinter-discuss] Techniques for creating tables/grids (was When to use a Canvas vs. a Frame from a container perspective?) In-Reply-To: <1292863271.18034.1411263663@webmail.messagingengine.com> References: <1292608339.1589.1410876097@webmail.messagingengine.com> <20101217215308.e4dd7ccc.klappnase@web.de> <1292620068.31850.1410907791@webmail.messagingengine.com> <1292780127.5452.1411111483@webmail.messagingengine.com> <20101220162249.GA15692@lairds.us> <1292863271.18034.1411263663@webmail.messagingengine.com> Message-ID: <20101220182455.4713f584.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Mon, 20 Dec 2010 11:41:11 -0500: > Cameron, > . > > While many valuable applications have been coded through the years > > using exactly this cell-in-Text technique, and the code above nicely > > demonstrates the promised scrolling, those focused on > > spreadsheet-like constructs will want to know about > http://tkinter.unpythonic.net/wiki/TkTable >. > > What is your opinion on using the new ttk Treeview control to implement > multi-cell tables and grids? > > My understanding is that one can configure the Treeview control as a > single level, multi-column list/grid and then float a borderless > Toplevel window with an input widget over the current Treeview "cell" to > allow for input? Disclaimer: I haven't tried this yet. Tktreectrl has a built-in feature that does exactly what you describe. However to make it really functional it requires some extra tweaking by the programmer and it is also relativeley slow. Obviously it is designed for occasional use , e.g. explorer-alike file renaming in a directory listing. To add this from scratch for the ttk.Treeview and building a spreadsheet from it will probably be quite a lot of work for a relatively poor result. For a very simple spreadsheet widget that comes with the standard library the Tix.Grid seems to be the widget of choice. If this is not capable enough I believe tktable is the best bet. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Insults are effective only where emotion is present. -- Spock, "Who Mourns for Adonais?" stardate 3468.1 From klappnase at web.de Mon Dec 20 19:11:22 2010 From: klappnase at web.de (Michael Lange) Date: Mon, 20 Dec 2010 19:11:22 +0100 Subject: [Tkinter-discuss] Using 3rd party Tk/Tcl libraries with Python/Tkinter In-Reply-To: <1292865480.30774.1411269615@webmail.messagingengine.com> References: <1292865480.30774.1411269615@webmail.messagingengine.com> Message-ID: <20101220191122.1d738137.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Mon, 20 Dec 2010 12:18:00 -0500: > >From time to time I've seen Tkinter developers reference 3rd party > Tk/Tcl libraries. Some examples are the PMW widgets, TkDnd, and TkTable. Pmw was added mistakenly to this list, it is 100% pure Python :) > > Here are some questions about these 3rd party components from the > perspective of a Python developer new to Tkinter (without any Tk/Tcl > experience): > > 1. Do these 3rd party components require compilation via a C compiler or > is there a repository with pre-compiled components for each platform? Depends, some extensions are pure tcl and thus can be used on any platform without compiling, e.g. the tablelist widget: http://www.nemethi.de/tablelist/tablelist.html For extensions written in C, in most cases you will find a windows binary file or installer on the project's web pages and a source code distribution for unix. However on most unix systems binaries of one or the other tk extensions are already included. > > 2. Are there issues related to what version of Python a developer is > using, eg. each release of Python uses a different version of Tk/Tcl? Most Tk extensions I have seen work fine with tk-8.4 - 8.6 , but again, your mileage may vary. For example , I couldn't get tkdnd to work on debian lenny, which however seems to be a problem with something else on my debian system, not Tk. If you want to install a precompiled windows binary you will have to pick the one that matches your Tk version of course. > > 3. Where do these component's library files get placed on Windows, > Linux, and Mac OS's? On windows the folder containing the library files must be copied into python's tcl distribution, usually something like c:\Python26\tcl . On unix systems the ./configure && make && make install process will usually (if all goes well) find automagically where to install the extension, depending on where tcl/tk is installed, usually this is /usr/lib. > > What I understand so far is that one must find or create Python wrapper > code in order to use 3rd party Tk/Tcl libraries. After that I'm stuck ;) Yes, in order to use these extensions from tcl, one has to call package require packagename which is similar to python's "import packagename" statement. So the python wrapper must call this "require" command and then implement the additional tcl functionality the package provides, all through the widget.tk.call () mechanism that allows to execute tcl commands from python. > > BTW: My personal interest is in solutions that work with Python 2.7 for > Windows but I thought I'd ask this question in a way that all Python > developers might benefit. There is no principle difference in this between python-2.7 and earlier versions, as long as the tk-version python uses is supported by the extension. Of course the syntax of the wrapper module must be supported by your python version either, but if you are using a current python, this will hardly ever be a problem. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. If I can have honesty, it's easier to overlook mistakes. -- Kirk, "Space Seed", stardate 3141.9 From Vasilis.Vlachoudis at cern.ch Mon Dec 20 21:15:35 2010 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Mon, 20 Dec 2010 20:15:35 +0000 Subject: [Tkinter-discuss] (no subject) In-Reply-To: <20101220181209.582f11da.klappnase@web.de> References: <0BC70B5D93E054469872FFD0FE07220E042B14@PLOXCHG13.cern.ch>, <20101220181209.582f11da.klappnase@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E042D26@PLOXCHG13.cern.ch> Thank you Michael. it works nicely V. ________________________________________ From: tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: 20 December 2010 18:12 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] (no subject) Hi Thus spoketh Vasilis Vlachoudis unto us on Mon, 20 Dec 2010 14:05:33 +0000: > Dear all, > > the default behavior of the Entry/Text on how they react to Cut&Paste > is a bit problematic (at least on linux) Imaging that the entry > contains the text "foobar" with the first 3 letters "foo" highlighted > and we have the word "test" copied previously on the clipboard. When we > press Ctrl-V to paste the clipboard text "test", tk will not delete the > "foo" before inserting the "test" and we will get the text "footestbar" > with the "foo" still highlighted. (The "test" will be inserted at the > location of the cursor) > > Normally what the user will expect will be to delete first the "foo" > and then insert the "test" getting the string "testbar" with the "test" > highlighted. > > Do you know how I can change the behavior without the need to override > the default Entry class and substitute it in the whole project? This behavior is intentional by Tk developers, maybe it matched some old Motif standard, I don't know for sure. The binding is defined in entry.tcl as binding to the virtual <> event: ################################## bind Entry <> { global tcl_platform catch { if {[tk windowingsystem] ne "x11"} { catch { %W delete sel.first sel.last } } %W insert insert [::tk::GetSelection %W CLIPBOARD] tk::EntrySeeInsert %W } } ################################# You see, in the fourth line they omit the deleting of the selection on X11 systems. If you want to change this, you must define a new callback for <> events for the Entry class and use bind_class() to override the default binding. We can use most of the code from the default binding and "translate" it into python, where %W corresponds with the event's widget attribute, and the catch command works much like a try..except in python; the "special" tk commands need to be wrapped in the widget's tk.call() function: ###################################### from Tkinter import * root = Tk() def entry_paste(event): try: event.widget.delete('sel.first', 'sel.last') except TclError: pass# nothing is selected # in tk.call() use the widget's string representation event.widget._w # instead of event.widget, which is the widget instance itself text = event.widget.tk.call('::tk::GetSelection', event.widget._w, 'CLIPBOARD') event.widget.insert('insert', text) event.widget.tk.call('tk::EntrySeeInsert', event.widget._w) root.bind_class('Entry', '<>', entry_paste) # create an Entry to see if it works: Entry(root).pack() root.mainloop() ###################################### I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Vulcans do not approve of violence. -- Spock, "Journey to Babel", stardate 3842.4 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss From Vasilis.Vlachoudis at cern.ch Tue Dec 21 09:58:20 2010 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Tue, 21 Dec 2010 08:58:20 +0000 Subject: [Tkinter-discuss] Binding all children Message-ID: <0BC70B5D93E054469872FFD0FE07220E042F43@PLOXCHG13.cern.ch> Hi all, Based on the previous threads I added the nice scrolled.py implementation of a ScrollFrame in my application and now I wanted to bind the Button-4&5 and MouseWheel events to the scrolled frame. My frames are a bit crowded therefore the real area that belongs to the client-scrolledframe is minimal the rest is buttons labels lists etc... Therefore when I bind the ... on the frame, I never get the events when the cursor is above a label or any other widget (which is most of the time). For the moment after the creation of each frame I am calling a similar like the following function recursively def bind_childs(w): if w.bind("<4>"): return w.bind("<4>", button4) w.bind("<5>", button5) for child in w.winfo_children(): child.bind("<4>", button4) child.bind("<5>", button5) however I don't find it as a elegant and neat solution. Is there a way (like bind_all) to bind all children or to get the event if is is not handled by any of the children? Thanks in advance Vasilis -------------- next part -------------- An HTML attachment was scrubbed... URL: From waynejwerner at gmail.com Tue Dec 21 22:04:49 2010 From: waynejwerner at gmail.com (Wayne Werner) Date: Tue, 21 Dec 2010 15:04:49 -0600 Subject: [Tkinter-discuss] Transparent backgrounds in widgets? Message-ID: Hi, Is it possible to create say, a checkbutton widget with a transparent background? I'm trying to take an image and put some checkbuttons on it so I can mark certain locations (like on a map). I'll be using the canvas widget and placing the checkbuttons on the canvas, but when I do they have the horrid background. I can change the color of the background, but I would much prefer having a transparent one. Is this possible to do with the standard widgets or do I have to roll my own? Thanks, Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Dec 22 11:44:40 2010 From: klappnase at web.de (Michael Lange) Date: Wed, 22 Dec 2010 11:44:40 +0100 Subject: [Tkinter-discuss] Transparent backgrounds in widgets? In-Reply-To: References: Message-ID: <20101222114440.032219d5.klappnase@web.de> Hi, Thus spoketh Wayne Werner unto us on Tue, 21 Dec 2010 15:04:49 -0600: > Hi, > > Is it possible to create say, a checkbutton widget with a transparent > background? I'm trying to take an image and put some checkbuttons on it > so I can mark certain locations (like on a map). I'll be using the > canvas widget and placing the checkbuttons on the canvas, but when I do > they have the horrid background. I can change the color of the > background, but I would much prefer having a transparent one. > > Is this possible to do with the standard widgets or do I have to roll my > own? > I don't think there is support for background transparency in Tk. The best bet is probably to try something like this: from Tkinter import * root = Tk() img_off = PhotoImage( data='R0lGODlhFQANAKEAAJaWlu/v7////////yH5BAEAAAMALAAAAAAVAA0AAAIyhI8Ww80Jw3LNiI' 'uxpBXkv3GD9WkTR5ZCiHrqelJpycquWjszGOs33etIhsRcpYgMMgoAOw==') img_on = PhotoImage( data='R0lGODlhFQANAMIAAJaWlu/v7////wAAAP///////////////yH5BAEAAAQALAAAAAAVAA0AAANACLq' 'sQTDCRsOTUYnNucUZIAwDRwofSGhk2aIXqI1tCauruL1bKus1mw/DOr2GkqKphAx1ns0JwEKtRlfWbAyTAAA7') c = Checkbutton(root, indicatoron=False, image=img_off, selectimage=img_on, bd=0, selectcolor='', width=12, height=12) c.pack(padx=100, pady=100) root.mainloop() If you need text next to the checkbutton, you can create a canvas text element, instead of using the checkbutton's text option. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You'll learn something about men and women -- the way they're supposed to be. Caring for each other, being happy with each other, being good to each other. That's what we call love. You'll like that a lot. -- Kirk, "The Apple", stardate 3715.6 From prog at vtr.net Thu Dec 23 14:49:27 2010 From: prog at vtr.net (craf) Date: Thu, 23 Dec 2010 10:49:27 -0300 Subject: [Tkinter-discuss] Change control styles ttk.Scrollbar Message-ID: <1293112167.4492.4.camel@cristian-desktop> Hi. Is it possible to change the background color of a control ttk.Scrollbar?. In its standard options is Style, but this seems not to work: Example: s.configure('TScrollbar', background='#cccccc') no works. Thanks in advance. Regards. Cristian Abarz?a Ubuntu 9.10 - Gnome- Python 2.7 From klappnase at web.de Thu Dec 23 18:53:48 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 23 Dec 2010 18:53:48 +0100 Subject: [Tkinter-discuss] Change control styles ttk.Scrollbar In-Reply-To: <1293112167.4492.4.camel@cristian-desktop> References: <1293112167.4492.4.camel@cristian-desktop> Message-ID: <20101223185348.0efc399c.klappnase@web.de> Hi, Thus spoketh craf unto us on Thu, 23 Dec 2010 10:49:27 -0300: > Hi. > > Is it possible to change the background color of a control > ttk.Scrollbar?. > In its standard options is Style, but this seems not to work: > > Example: > > s.configure('TScrollbar', background='#cccccc') no works. > > Thanks in advance. Can you show a more detailed example of what you wanted to schieve and what exactly happened? I tried this short snippet, which works as expected: from Tkinter import * import ttk root = Tk() s=ttk.Style() s.configure('TScrollbar', background='red') sb = ttk.Scrollbar(root) sb.pack(side='right', fill='y') root.mainloop() Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No one wants war. -- Kirk, "Errand of Mercy", stardate 3201.7 From klappnase at web.de Thu Dec 23 20:12:55 2010 From: klappnase at web.de (Michael Lange) Date: Thu, 23 Dec 2010 20:12:55 +0100 Subject: [Tkinter-discuss] Binding all children In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E042F43@PLOXCHG13.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E042F43@PLOXCHG13.cern.ch> Message-ID: <20101223201255.1c50ce64.klappnase@web.de> Hi, Thus spoketh Vasilis Vlachoudis unto us on Tue, 21 Dec 2010 08:58:20 +0000: > Hi all, > > Based on the previous threads I added the nice scrolled.py > implementation of a ScrollFrame in my application and now I wanted to > bind the Button-4&5 and MouseWheel events to the scrolled frame. My > frames are a bit crowded therefore the real area that belongs to the > client-scrolledframe is minimal the rest is buttons labels lists etc... > Therefore when I bind the ... on the frame, I never get the > events when the cursor is above a label or any other widget (which is > most of the time). For the moment after the creation of each frame I am > calling a similar like the following function recursively > > def bind_childs(w): > if w.bind("<4>"): return > w.bind("<4>", button4) > w.bind("<5>", button5) > for child in w.winfo_children(): > child.bind("<4>", button4) > child.bind("<5>", button5) > > however I don't find it as a elegant and neat solution. > Is there a way (like bind_all) to bind all children or to get the event > if is is not handled by any of the children? I don't think it's that bad at all. If you have a lot of frames and children, maybe it is a bit nicer to define widget classes that save you to explicitely apply the bindings for any of your Frames and their children, like: class SLabel(Label): def __init__(self, *args, **kw): Label.__init__(self, *args, **kw) for seq in ('<4>', '<5>'): if self.master.bind(seq): self.bind(seq, self.master.bind(seq)) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Intuition, however illogical, is recognized as a command prerogative. -- Kirk, "Obsession", stardate 3620.7 From prog at vtr.net Thu Dec 23 21:06:59 2010 From: prog at vtr.net (craf) Date: Thu, 23 Dec 2010 17:06:59 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Change control styles ttk.Scrollbar] Message-ID: <1293134819.3247.2.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: Michael Lange > Para: tkinter-discuss at python.org > Asunto: Re: [Tkinter-discuss] Change control styles ttk.Scrollbar > Fecha: Thu, 23 Dec 2010 18:53:48 +0100 > > Hi, > > Thus spoketh craf > unto us on Thu, 23 Dec 2010 10:49:27 -0300: > > > Hi. > > > > Is it possible to change the background color of a control > > ttk.Scrollbar?. > > In its standard options is Style, but this seems not to work: > > > > Example: > > > > s.configure('TScrollbar', background='#cccccc') no works. > > > > Thanks in advance. > > Can you show a more detailed example of what you wanted to schieve and > what exactly happened? > I tried this short snippet, which works as expected: > > from Tkinter import * > import ttk > > root = Tk() > s=ttk.Style() > s.configure('TScrollbar', background='red') > sb = ttk.Scrollbar(root) > sb.pack(side='right', fill='y') > root.mainloop() > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > No one wants war. > -- Kirk, "Errand of Mercy", stardate 3201.7 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss Thanks Michael! Not because my example was not working and if yours. Anyway, your example helped me. Regards. Cristian From prog at vtr.net Tue Dec 28 19:12:11 2010 From: prog at vtr.net (craf) Date: Tue, 28 Dec 2010 15:12:11 -0300 Subject: [Tkinter-discuss] how to limit panel size Message-ID: <1293559931.4032.2.camel@cristian-desktop> Hi. There any way to limit the size of the panels a control ttk.Panedwindow. Regards. Cristian Abarz?a F. From prog at vtr.net Wed Dec 29 17:30:36 2010 From: prog at vtr.net (craf) Date: Wed, 29 Dec 2010 13:30:36 -0300 Subject: [Tkinter-discuss] Use underline Message-ID: <1293640236.6797.1.camel@cristian-desktop> Hi. I wonder how I can run the code button when you press alt-h. Use underline, but I can not connect. code: import Tkinter class App: def __init__(self, master): self.root = master b = Tkinter.Button(self.root, text='Hello', underline=0) b.pack() b.bind('', function) def function(event): print 'Ok' master = Tkinter.Tk() app = App(master) master.mainloop() thanks in advance Regards. Cristian Abarz?a From python at bdurham.com Wed Dec 29 19:52:08 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 29 Dec 2010 13:52:08 -0500 Subject: [Tkinter-discuss] Use underline In-Reply-To: <1293640236.6797.1.camel@cristian-desktop> References: <1293640236.6797.1.camel@cristian-desktop> Message-ID: <1293648728.7352.1412689633@webmail.messagingengine.com> Cristian, You have to bind your Alt key presses separately. The underline= only underlines the letter - it does not bind to an event handler. Here's a snippet that may give you some ideas. Disclaimer: I'm not sure if its best practice or not. Malcolm """ Treat Alt+I as a shortcut keystroke for the Insert button """ import Tkinter as tk import ttk def onClick( event=None ): if event: print event.keysym, event.keysym_num, event.state # event.state == 131104 regardless of left or right alt key if event.keysym == 'i' and event.state == 131104: pass else: return button1.focus_set() entry1.delete( 0, 'end' ) entry1.insert( 'end', '' ) root = tk.Tk() style = dict( padx=24, pady=24 ) entry1 = tk.Entry( root ) entry1.pack( **style ) entry2 = tk.Entry( root ) entry2.pack( **style ) button1 = ttk.Button( root, text='Insert text', underline=0, command=onClick ) button1.pack( **style ) # bind shortcut keystrokes at the outermost container root.bind( '', onClick ) root.mainloop() From prog at vtr.net Wed Dec 29 20:27:04 2010 From: prog at vtr.net (craf) Date: Wed, 29 Dec 2010 16:27:04 -0300 Subject: [Tkinter-discuss] [Fwd: Re: Use underline] Message-ID: <1293650824.2236.1.camel@cristian-desktop> --------- Mensaje reenviado -------- > De: python at bdurham.com > Para: craf , Python Tkinter Ingles > > Asunto: Re: [Tkinter-discuss] Use underline > Fecha: Wed, 29 Dec 2010 13:52:08 -0500 > > Cristian, > > You have to bind your Alt key presses separately. The underline= only > underlines the letter - it does not bind to an event handler. > > Here's a snippet that may give you some ideas. Disclaimer: I'm not sure > if its best practice or not. > > Malcolm > > > """ > Treat Alt+I as a shortcut keystroke for the Insert button > """ > > import Tkinter as tk > import ttk > > def onClick( event=None ): > if event: > print event.keysym, event.keysym_num, event.state > > # event.state == 131104 regardless of left or right alt > key > if event.keysym == 'i' and event.state == 131104: > pass > else: > return > > button1.focus_set() > entry1.delete( 0, 'end' ) > entry1.insert( 'end', '' ) > > root = tk.Tk() > > style = dict( padx=24, pady=24 ) > entry1 = tk.Entry( root ) > entry1.pack( **style ) > entry2 = tk.Entry( root ) > entry2.pack( **style ) > > button1 = ttk.Button( root, text='Insert text', underline=0, > command=onClick ) > button1.pack( **style ) > > # bind shortcut keystrokes at the outermost container > root.bind( '', onClick ) > > root.mainloop() Thanks Malcom for the Tips! Regards. Cristian Abarz?a F. From python at bdurham.com Thu Dec 30 20:42:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 30 Dec 2010 14:42:46 -0500 Subject: [Tkinter-discuss] Tkinter accessability options Message-ID: <1293738166.29962.1412836337@webmail.messagingengine.com> I'm cross-posting this thread from python-list. > Not all the people were happy because the darkness disappeared partially for some of them and more and more blind people started to use a computer, and discovered that the Tk interfaces are absolutely inaccessible for them. Might this package help? (I have no experience with this project) Tka11y 0.1.1 - accessibility-aware Tkinter http://pypi.python.org/pypi/Tka11y Another idea: Use Tkinter's events to speak TTS descriptions of the current control and/or its contents? I would love to hear from anyone using either of these techniques ... or other techniques or screen reader products ... to make their Tkinter applications accessible to low vision/blind users. Malcolm From python at bdurham.com Thu Dec 30 22:49:43 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 30 Dec 2010 16:49:43 -0500 Subject: [Tkinter-discuss] Re-arrange ttk.treeview columns via drag and drop? Message-ID: <1293745783.1564.1412851147@webmail.messagingengine.com> Is there a way to for users to re-arrange column order in the ttk.treeview widget? Many grid-like user interfaces allow a user to drag and drop columns to change column order. Any such capability present in the ttk.treeview widget? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Dec 31 13:37:17 2010 From: klappnase at web.de (Michael Lange) Date: Fri, 31 Dec 2010 13:37:17 +0100 Subject: [Tkinter-discuss] Re-arrange ttk.treeview columns via drag and drop? In-Reply-To: <1293745783.1564.1412851147@webmail.messagingengine.com> References: <1293745783.1564.1412851147@webmail.messagingengine.com> Message-ID: <20101231133717.0d7119ac.klappnase@web.de> Hi, Thus spoketh python at bdurham.com unto us on Thu, 30 Dec 2010 16:49:43 -0500: > Is there a way to for users to re-arrange column order in the > ttk.treeview widget? Many grid-like user interfaces allow a user > to drag and drop columns to change column order. Any such > capability present in the ttk.treeview widget? You can change the order of the columns with the treeview's displaycolumns option. The dnd handling seems to be a perfect task for the Tkdnd module, just look at the module's demo code, it shouldn't be too hard to figure out how it works. Regards, and a happy new year! Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Suffocating together ... would create heroic camaraderie. -- Khan Noonian Singh, "Space Seed", stardate 3142.8