From land.d.fleming at nasa.gov Thu Jan 2 21:59:44 2014 From: land.d.fleming at nasa.gov (Fleming, Land D. (JSC-ER111)[Jacobs Technology, Inc.]) Date: Thu, 2 Jan 2014 20:59:44 +0000 Subject: [Tkinter-discuss] Issues converting TKinter application to Ttk Message-ID: <7BCA418C6A9239438E0F852E4E1EB9DE049658@NDJSMBX103.ndc.nasa.gov> I have a Tkinter application that runs as intended, but I'm in the process of converting it to Ttk in order to get some of the new widget classes Ttk provides. I'm using Python 2.7.5 on a Windows 7 machine. I've run into two serious problems doing the conversion that I've been able to find work-arounds for, but I'm not sure if the problems are associated with undocumented peculiarities with Ttk or if I'm doing something wrong. I describe the application and the two problems below. I've worked with Tkinter for several months but only recently tried to using Ttk. If anyone knows of a repository where issues like these are documented, please let me know. Thanks The application frame is a subclass of PanedWindow defined as follows: import sys, os from Tkinter import * import ttk from ttk import * class App(ttk.PanedWindow): ... def __init__(self, master, **panedWindowOpts): PanedWindow.__init__(self, master, **panedWindowOpts) First problem: I found that the styles I defined for widgets in the application were ignored when I made the application's master an instance of Tk() as follows: root = Tk() app = App(root, style='My.TPanedwindow', orient=VERTICAL) After considerable trial and error (mostly error) I found that the styles worked as advertised, if I changed the application master to an instance of Toplevel rather than of Tk: top = Toplevel() app = App(top, style='My.TPanedwindow', orient=VERTICAL) top.mainloop() Second Problem: When the mainloop executed as above, what appeared to be an extraneous blank window was stacked on top of the application window. This window didn't appear when I was using basic Tkinter. I noticed that if I killed the extraneous window by clicking on the "X" in the window's upper right corner, it also killed the application, which suggested the "extraneous" window was really the root window. After searching the documentation and much trial and error, I found that I could get the root window to go away without killing my app by explicitly calling withdraw() on the root before running the mainloop: Tkinter._default_root.withdraw() app.mainloop() This would have been a show stopper if I hadn't been able to work around it, because I couldn't give an application to end users that pops up a meaningless empty window that they have to close themselves. I wasn't able to locate much documentation on the root window, and I only found out about _default_root by looking at Tkinter.py. Further, I found nothing to indicate that the root had a withdraw method, and just tried it after running out of all other options I could think of. Luckily, it worked. -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Jan 3 09:42:49 2014 From: klappnase at web.de (Michael Lange) Date: Fri, 3 Jan 2014 09:42:49 +0100 Subject: [Tkinter-discuss] Issues converting TKinter application to Ttk In-Reply-To: <7BCA418C6A9239438E0F852E4E1EB9DE049658@NDJSMBX103.ndc.nasa.gov> References: <7BCA418C6A9239438E0F852E4E1EB9DE049658@NDJSMBX103.ndc.nasa.gov> Message-ID: <20140103094249.f2c53eff075d6154399c122f@web.de> Hi, On Thu, 2 Jan 2014 20:59:44 +0000 "Fleming, Land D. (JSC-ER111)[Jacobs Technology, Inc.]" wrote: > First problem: > > I found that the styles I defined for widgets in the application were > ignored when I made the application's master an instance of Tk() as > follows: > > root = Tk() > app = App(root, style='My.TPanedwindow', orient=VERTICAL) > > After considerable trial and error (mostly error) I found that the > styles worked as advertised, if I changed the application master to an > instance of Toplevel rather than of Tk: > > top = Toplevel() > app = App(top, style='My.TPanedwindow', orient=VERTICAL) > top.mainloop() I haven't worked much with custom styles so far, so I cannot tell why this happens. Maybe you could try to define the My.TPanedwindow style within the App class to work around this? > Second Problem: > > When the mainloop executed as above, what appeared to be an extraneous > blank window was stacked on top of the application window. This window > didn't appear when I was using basic Tkinter. I noticed that if I > killed the extraneous window by clicking on the "X" in the window's > upper right corner, it also killed the application, which suggested the > "extraneous" window was really the root window. After searching the > documentation and much trial and error, I found that I could get the > root window to go away without killing my app by explicitly calling > withdraw() on the root before running the mainloop: > > Tkinter._default_root.withdraw() > app.mainloop() > > This would have been a show stopper if I hadn't been able to work > around it, because I couldn't give an application to end users that > pops up a meaningless empty window that they have to close themselves. > I wasn't able to locate much documentation on the root window, and I > only found out about _default_root by looking at Tkinter.py. Further, I > found nothing to indicate that the root had a withdraw method, and just > tried it after running out of all other options I could think of. > Luckily, it worked. The reason that _default_root is not documented is that it is an internal or "private" attribute which at least in theory might be changed by the Tkinter developers, which is told us by the leading underscore character (although I believe in the case of _default_root it is rather safe to use it anyway). The "proper" way to have a Toplevel as main application window is something like: root = Tk() root.withdraw() top = Toplevel(root) # make sure clicking the window's "X" button does not only # close the Toplevel but the application altogether: top.protocol('WM_DELETE_WINDOW', root.quit) (...) root.mainloop() root.destroy() As far as documentation is concerned, there are at least two excellent reference manuals available online: http://effbot.org/tkinterbook/tkinter-index.htm by Frederik Lundh and http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html by John W. Shipman. (the latter however doesn't mention explicitely at the Toplevel page that the Toplevel's methods are also valid for Tk instances, the first one does ;) . Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. One does not thank logic. -- Sarek, "Journey to Babel", stardate 3842.4 From land.d.fleming at nasa.gov Mon Jan 6 17:22:33 2014 From: land.d.fleming at nasa.gov (Fleming, Land D. (JSC-ER111)[Jacobs Technology, Inc.]) Date: Mon, 6 Jan 2014 16:22:33 +0000 Subject: [Tkinter-discuss] Issues converting TKinter application to Ttk In-Reply-To: <20140103094249.f2c53eff075d6154399c122f@web.de> References: <7BCA418C6A9239438E0F852E4E1EB9DE049658@NDJSMBX103.ndc.nasa.gov> <20140103094249.f2c53eff075d6154399c122f@web.de> Message-ID: <7BCA418C6A9239438E0F852E4E1EB9DE04A7B0@NDJSMBX103.ndc.nasa.gov> Thanks for your suggestions. I substituted Tk() for _default_root, but I ran into the same problem with an extra window superimposed over the application window. I'm wondering if the problem is associated with my use of my own subclass of Frame as the application rather than just an instance of Frame itself. All the examples I've found for ttk so far use Frame as the application, with all the widgets created in the main body of the Python script, rather than in an application __init__ method. I'm going to stay with _default_root and its withdraw method for now, since it's an easy workaround for a really bad problem. BTW: I had noticed that the application wasn't returning to the IDLE command prompt when I clicked the Windows "X" button, so I knew the root process was still running after the window was closed. Thanks for telling me about the protocol method and 'WM_DELETE_WINDOW'. I hadn't known about it. I found that calling top.protocol('WM_DELETE_WINDOW', root.destroy) did the trick, although root.quit just made the application hang rather than close. Thanks again for your help. Land -----Original Message----- From: Tkinter-discuss [mailto:tkinter-discuss-bounces+land.d.fleming=nasa.gov at python.org] On Behalf Of Michael Lange Sent: Friday, January 03, 2014 2:43 AM To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Issues converting TKinter application to Ttk Hi, On Thu, 2 Jan 2014 20:59:44 +0000 "Fleming, Land D. (JSC-ER111)[Jacobs Technology, Inc.]" wrote: > First problem: > > I found that the styles I defined for widgets in the application were > ignored when I made the application's master an instance of Tk() as > follows: > > root = Tk() > app = App(root, style='My.TPanedwindow', orient=VERTICAL) > > After considerable trial and error (mostly error) I found that the > styles worked as advertised, if I changed the application master to an > instance of Toplevel rather than of Tk: > > top = Toplevel() > app = App(top, style='My.TPanedwindow', orient=VERTICAL) > top.mainloop() I haven't worked much with custom styles so far, so I cannot tell why this happens. Maybe you could try to define the My.TPanedwindow style within the App class to work around this? > Second Problem: > > When the mainloop executed as above, what appeared to be an extraneous > blank window was stacked on top of the application window. This window > didn't appear when I was using basic Tkinter. I noticed that if I > killed the extraneous window by clicking on the "X" in the window's > upper right corner, it also killed the application, which suggested > the "extraneous" window was really the root window. After searching > the documentation and much trial and error, I found that I could get > the root window to go away without killing my app by explicitly > calling > withdraw() on the root before running the mainloop: > > Tkinter._default_root.withdraw() > app.mainloop() > > This would have been a show stopper if I hadn't been able to work > around it, because I couldn't give an application to end users that > pops up a meaningless empty window that they have to close themselves. > I wasn't able to locate much documentation on the root window, and I > only found out about _default_root by looking at Tkinter.py. Further, > I found nothing to indicate that the root had a withdraw method, and > just tried it after running out of all other options I could think of. > Luckily, it worked. The reason that _default_root is not documented is that it is an internal or "private" attribute which at least in theory might be changed by the Tkinter developers, which is told us by the leading underscore character (although I believe in the case of _default_root it is rather safe to use it anyway). The "proper" way to have a Toplevel as main application window is something like: root = Tk() root.withdraw() top = Toplevel(root) # make sure clicking the window's "X" button does not only # close the Toplevel but the application altogether: top.protocol('WM_DELETE_WINDOW', root.quit) (...) root.mainloop() root.destroy() As far as documentation is concerned, there are at least two excellent reference manuals available online: http://effbot.org/tkinterbook/tkinter-index.htm by Frederik Lundh and http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html by John W. Shipman. (the latter however doesn't mention explicitely at the Toplevel page that the Toplevel's methods are also valid for Tk instances, the first one does ;) . Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. One does not thank logic. -- Sarek, "Journey to Babel", stardate 3842.4 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From guido at python.org Wed Jan 15 05:04:52 2014 From: guido at python.org (Guido van Rossum) Date: Tue, 14 Jan 2014 20:04:52 -0800 Subject: [Tkinter-discuss] [Python-Dev] Binding problem In-Reply-To: References: Message-ID: Hey Rob, The place to get help with Tkinter is tkinter-discuss at python.org. I've CC'ed that list for you. --Guido On Tue, Jan 14, 2014 at 4:53 PM, Rob Ward wrote: > I apologise if I have come to the wrong place here, but 12hrs searching, > plus experimenting, on the WWW for advice on it has not yielded any > successful advice to resolve the issue. > > I am am having trouble binding an Entry widget to > > Here is the snippet (butCol is a Frame widget to put buttons,labels and text > entry down LHS) > > KS1=StringVar() > KS1.set("Key is ??") > butCol.ks1 > =Label(butCol,textvariable=KS1).grid(column=0,row=18,sticky=(N,W)) > > myKey = [0,2,4,5,7,9,11] #Begin in the key of C > KS2 =StringVar() > KS2.set("C") > butCol.ks2 > =Entry(butCol,width=20,textvariable=KS2).grid(column=0,row=19,sticky=(N,W)) > > The above lines all render correctly, but will not trigger off "entry" of > data at all on > > Adding the following line just crashes. > > butCol.ks2.bind("",chooseKey) > > I downloaded the Python 3 package from the recommended site last week to > begin this project (it was previously working OK in Skulptor, but I was not > prepared to develop it any further in that environment, though it was an > excellent starting environment). So I believe the Python language installed > is up todate. I have not previously installed Python so it should be > "clean". > > If you could give any direct advice I would be very grateful or if you can > direct me to your best "forum" site maybe I could use that. > > One overall observation that has frustrated me is how toi search for > information that relates to Python3 and the latest tkinter modules. I kept > finding old python or old Tkinter or combinations of both. Wrorking my way > through this was very time consuming and rarely productive. Is there any > advice on how to get the "latest" information off the WWW? > > > > Cheers, Rob Ward > > PS In my state of eternal optimism I have attached the whole file :-) > > PPS I have done some OOP in the past but not keen to jump in at the moment. > > > _______________________________________________ > Python-Dev mailing list > Python-Dev at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/guido%40python.org > -- --Guido van Rossum (python.org/~guido) From klappnase at web.de Wed Jan 15 10:22:01 2014 From: klappnase at web.de (Michael Lange) Date: Wed, 15 Jan 2014 10:22:01 +0100 Subject: [Tkinter-discuss] [Python-Dev] Binding problem In-Reply-To: References: Message-ID: <20140115102201.2c783d6d09880f7a3cf1a134@web.de> Hi Rob, > On Tue, Jan 14, 2014 at 4:53 PM, Rob Ward wrote: (...) > > I am am having trouble binding an Entry widget to > > > > Here is the snippet (butCol is a Frame widget to put buttons,labels > > and text entry down LHS) > > > > KS1=StringVar() > > KS1.set("Key is ??") > > butCol.ks1 > > =Label(butCol,textvariable=KS1).grid(column=0,row=18,sticky=(N,W)) > > > > myKey = [0,2,4,5,7,9,11] #Begin in the key of C > > KS2 =StringVar() > > KS2.set("C") > > butCol.ks2 > > =Entry(butCol,width=20,textvariable=KS2).grid(column=0,row=19,sticky= > > (N,W)) > > > > The above lines all render correctly, but will not trigger off > > "entry" of data at all on Yes, by default pressing the Retrun key on an Entry widget simply does nothing. > > > > Adding the following line just crashes. > > > > butCol.ks2.bind("",chooseKey) I cannot reproduce this crashing here, so I suspect it might have something to do with chooseKey() ? To help to track down the problem you might try to run the following very simple example: from tkinter import * root = Tk() var = StringVar() var.set('foo') l = Label(root, textvariable=var) l.pack() def test(event): print(var.get()) e = Entry(root, textvariable=var) e.pack() e.bind('', test) root.mainloop() Does this work for you or crash either? (...) > > One overall observation that has frustrated me is how toi search for > > information that relates to Python3 and the latest tkinter modules. > > I kept finding old python or old Tkinter or combinations of both. > > Wrorking my way through this was very time consuming and rarely > > productive. Is there any advice on how to get the "latest" > > information off the WWW? There are at least two excellent Tkinter reference manuals available online: http://effbot.org/tkinterbook/tkinter-index.htm by Frederik Lundh and http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html by John W. Shipman. There are practically no changes in Tkinter between Python2 and -3 (except that Tkinter in Python3 is now spelled "tkinter" :), so both of these are still valid. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. I object to intellect without discipline; I object to power without constructive purpose. -- Spock, "The Squire of Gothos", stardate 2124.5 From bryan.oakley at gmail.com Wed Jan 15 12:50:36 2014 From: bryan.oakley at gmail.com (Bryan Oakley) Date: Wed, 15 Jan 2014 05:50:36 -0600 Subject: [Tkinter-discuss] [Python-Dev] Binding problem In-Reply-To: References: Message-ID: When you do this: butCol.ks2=Entry(...).grid(...) .... you are setting butCol to None, because .grid(...) returns None. Separate the widget creation and widget layout into two distinct steps so that butCol.ks2 has an actual value: butCol.ks2 = Entry(...) butCol.ks2.grid(...) This should then allow the bind to work. On Tue, Jan 14, 2014 at 10:04 PM, Guido van Rossum wrote: > Hey Rob, > > The place to get help with Tkinter is tkinter-discuss at python.org. I've > CC'ed that list for you. > > --Guido > > On Tue, Jan 14, 2014 at 4:53 PM, Rob Ward wrote: > > I apologise if I have come to the wrong place here, but 12hrs searching, > > plus experimenting, on the WWW for advice on it has not yielded any > > successful advice to resolve the issue. > > > > I am am having trouble binding an Entry widget to > > > > Here is the snippet (butCol is a Frame widget to put buttons,labels and > text > > entry down LHS) > > > > KS1=StringVar() > > KS1.set("Key is ??") > > butCol.ks1 > > =Label(butCol,textvariable=KS1).grid(column=0,row=18,sticky=(N,W)) > > > > myKey = [0,2,4,5,7,9,11] #Begin in the key of C > > KS2 =StringVar() > > KS2.set("C") > > butCol.ks2 > > > =Entry(butCol,width=20,textvariable=KS2).grid(column=0,row=19,sticky=(N,W)) > > > > The above lines all render correctly, but will not trigger off "entry" of > > data at all on > > > > Adding the following line just crashes. > > > > butCol.ks2.bind("",chooseKey) > > > > I downloaded the Python 3 package from the recommended site last week to > > begin this project (it was previously working OK in Skulptor, but I was > not > > prepared to develop it any further in that environment, though it was an > > excellent starting environment). So I believe the Python language > installed > > is up todate. I have not previously installed Python so it should be > > "clean". > > > > If you could give any direct advice I would be very grateful or if you > can > > direct me to your best "forum" site maybe I could use that. > > > > One overall observation that has frustrated me is how toi search for > > information that relates to Python3 and the latest tkinter modules. I > kept > > finding old python or old Tkinter or combinations of both. Wrorking my > way > > through this was very time consuming and rarely productive. Is there any > > advice on how to get the "latest" information off the WWW? > > > > > > > > Cheers, Rob Ward > > > > PS In my state of eternal optimism I have attached the whole file :-) > > > > PPS I have done some OOP in the past but not keen to jump in at the > moment. > > > > > > _______________________________________________ > > Python-Dev mailing list > > Python-Dev at python.org > > https://mail.python.org/mailman/listinfo/python-dev > > Unsubscribe: > > https://mail.python.org/mailman/options/python-dev/guido%40python.org > > > > > > -- > --Guido van Rossum (python.org/~guido) > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rl.ward at bigpond.com Wed Jan 15 07:56:38 2014 From: rl.ward at bigpond.com (Rob Ward) Date: Wed, 15 Jan 2014 17:56:38 +1100 Subject: [Tkinter-discuss] Bind to a an Entry widget problems (tkinter/python3) Message-ID: I apologise if I have come to the wrong place here, but 12hrs searching, plus experimenting, on the WWW for advice on it has not yielded any successful advice to resolve the issue. I am am having trouble binding an Entry widget to Here is the snippet (butCol is a Frame widget to put buttons,labels and text entry down LHS) KS1=StringVar() KS1.set("Key is ??") butCol.ks1 =Label(butCol,textvariable=KS1).grid(column=0,row=18,sticky=(N,W)) myKey = [0,2,4,5,7,9,11] #Begin in the key of C KS2 =StringVar() KS2.set("C") butCol.ks2 =Entry(butCol,width=20,textvariable=KS2).grid(column=0,row=19,sticky=(N,W)) The above lines all render correctly, but will not trigger off "entry" of data at all on Adding the following line just crashes. butCol.ks2.bind("",chooseKey) I downloaded the Python 3 package from the recommended site last week to begin this project (it was previously working OK in Skulptor, but I was not prepared to develop it any further in that environment, though it was an excellent starting environment). So I believe the Python language installed is up todate. I have not previously installed Python so it should be "clean". If you could give any direct advice I would be very grateful. One overall observation that has frustrated me is how toi search for information that relates to Python3 and the latest tkinter modules. I kept finding old python or old Tkinter or combinations of both. Wrorking my way through this was very time consuming and rarely productive. Is there any advice on how to get the "latest" information off the WWW? Cheers, Rob Ward PS In my state of eternal optimism I have attached the whole file :-) PPS I have done some OOP in the past but not keen to jump in at the moment. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: myGui07.py URL: From rl.ward at bigpond.com Thu Jan 16 07:06:26 2014 From: rl.ward at bigpond.com (Rob Ward) Date: Thu, 16 Jan 2014 17:06:26 +1100 Subject: [Tkinter-discuss] Binding a List to a ScrollBar Message-ID: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> Hi Folks, Sorry to be back so soon but I have another challenge. I wanted to choose some colours for my program and came across a program that claimed to list the colours in a nifty little Python program. Cute I thought, I must try that. Quite a few hours later I am stumped. Here is the code with only the first 26 colours as data - from tkinter import * COLORS =['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace', 'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff', 'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', 'lavender', 'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', 'slate gray', 'light slate gray', 'gray', 'light grey'] root = Tk() scrollbar = Scrollbar(root) scrollbar.pack( side = RIGHT, fill=Y ) mylist = Listbox(root, yscrollcommand = scrollbar.set ) for c in COLORS: e = Label(mylist, text = c, background = c) mylist.insert(END,e ) e.pack(fill=X)#Problem line???? mylist.pack( side = LEFT, fill = BOTH ) scrollbar.config( command = mylist.yview ) mainloop() As you can see I have an interesting line shown as a "Problem line????". If this line is out I get a list of pairs of number showing the default 10 lines and the list of numbers is "scrollable". However if the line is in as shown above, I get a list 26 lines long, with the lovely colours nicely shown. If I drag the list to a shorter size, the scroll bar appears but its movement does not link with the list. It goes up an down nicely but the list stays still. This is rather inconvenient when trying to view the complete list of colours, which is 479 high! Thanks in anticipation of anyone being able to help me, it will be very much appreciated. Cheers, Rob -------------- next part -------------- An HTML attachment was scrubbed... URL: From niccokunzmann at rambler.ru Thu Jan 16 09:50:40 2014 From: niccokunzmann at rambler.ru (Nicco Kunzmann) Date: Thu, 16 Jan 2014 09:50:40 +0100 Subject: [Tkinter-discuss] Binding a List to a ScrollBar In-Reply-To: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> References: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> Message-ID: <52D79D60.8010308@rambler.ru> Hello Rob, as far as I remember you can only insert text into a Listbox. Maybe you pack Widgets onto a Listbox they appear but it does not make them items. Try this: mylist.insert(END,*c* ) mylist.itemconfigure(END, background = c) If you want to change the background. Greetings, Nicco Am 16.01.2014 07:06, schrieb Rob Ward: > Hi Folks, > Sorry to be back so soon but I have another challenge. I wanted to > choose some colours for my program and came across a program that > claimed to list the colours in a nifty little Python program. Cute I > thought, I must try that. Quite a few hours later I am stumped. Here > is the code with only the first 26 colours as data - > > from tkinter import * > > COLORS =['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral > white', 'old lace', > 'linen', 'antique white', 'papaya whip', 'blanched almond', > 'bisque', 'peach puff', > 'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice > blue', 'lavender', > 'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', > 'slate gray', > 'light slate gray', 'gray', 'light grey'] > > root = Tk() > scrollbar = Scrollbar(root) > scrollbar.pack( side = RIGHT, fill=Y ) > > mylist = Listbox(root, yscrollcommand = scrollbar.set ) > for c in COLORS: > e = Label(mylist, text = c, background = c) > mylist.insert(END,e ) > e.pack(fill=X)#Problem line???? > > mylist.pack( side = LEFT, fill = BOTH ) > scrollbar.config( command = mylist.yview ) > > mainloop() > As you can see I have an interesting line shown as a "Problem > line????". If this line is out I get a list of pairs of number showing > the default 10 lines and the list of numbers is "scrollable". > However if the line is in as shown above, I get a list 26 lines long, > with the lovely colours nicely shown. If I drag the list to a shorter > size, the scroll bar appears but its movement does not link with the > list. It goes up an down nicely but the list stays still. This is > rather inconvenient when trying to view the complete list of colours, > which is 479 high! > > Thanks in anticipation of anyone being able to help me, it will be > very much appreciated. > > Cheers, Rob > > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Jan 16 10:10:20 2014 From: klappnase at web.de (Michael Lange) Date: Thu, 16 Jan 2014 10:10:20 +0100 Subject: [Tkinter-discuss] Binding a List to a ScrollBar In-Reply-To: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> References: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> Message-ID: <20140116101020.25100865eebcbf49f3e3f393@web.de> Hi, On Thu, 16 Jan 2014 17:06:26 +1100 "Rob Ward" wrote: > Hi Folks, > Sorry to be back so soon but I have another challenge. No problem, that's what this list was made for ;) (...) > mylist = Listbox(root, yscrollcommand = scrollbar.set ) > for c in COLORS: > e = Label(mylist, text = c, background = c) > mylist.insert(END,e ) > e.pack(fill=X)#Problem line???? > > mylist.pack( side = LEFT, fill = BOTH ) > scrollbar.config( command = mylist.yview ) You are trying here to use the Listbox as a kind of "scrollable Frame" widget which apparently does not work as expected. If you really want to have a scrolled Frame widget in Tkinter you will have to use some "3rd party" widget; I never actually used it myself, but I think the ScrolledWindow widget that comes with the standard library's Tix module should be usable. There is also a ScrolledFrame widget that comes with Pmw (http://pmw.sf.net). There are also some "standalone" ScrolledFrame widgets available, that may or may not be Python3-compatible. For your particular case it looks like the good news is that you need none of these (at least if I understood correctly what you want to achieve), because you can simply make use of the Listboxes itemconfigure command, as in: mylist = Listbox(root, yscrollcommand = scrollbar.set ) i = 0 for c in COLORS: mylist.insert(END,c) mylist.itemconfigure(i, background=c) i += 1 If you are really ambitious you can even try to change each item's foreground, selectbackground and selectforeground colors appropriate to its background. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Blast medicine anyway! We've learned to tie into every organ in the human body but one. The brain! The brain is what life is all about. -- McCoy, "The Menagerie", stardate 3012.4 From bryan.oakley at gmail.com Thu Jan 16 13:05:08 2014 From: bryan.oakley at gmail.com (Bryan Oakley) Date: Thu, 16 Jan 2014 06:05:08 -0600 Subject: [Tkinter-discuss] Binding a List to a ScrollBar In-Reply-To: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> References: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> Message-ID: A listbox can only scroll text. So, to display a colored word you would use the "itemconfig" method to change the background and foreground of each element individually. For example: for index, color in enumerate(colors): listbox.insert("end", color) listbox.itemconfig(index, foreground=color) If you really want to create a list of widgets, you'll have to either embed the widgets in a canvas, put the widgets in a frame and put the frame in a canvas, or put the widgets in a text widget (canvas and text widgets being the two widgets that support vertical scrolling) On Thu, Jan 16, 2014 at 12:06 AM, Rob Ward wrote: > Hi Folks, > Sorry to be back so soon but I have another challenge. I wanted to choose > some colours for my program and came across a program that claimed to list > the colours in a nifty little Python program. Cute I thought, I must try > that. Quite a few hours later I am stumped. Here is the code with only the > first 26 colours as data - > > from tkinter import * > > COLORS =['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral > white', 'old lace', > 'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', > 'peach puff', > 'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', > 'lavender', > 'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', 'slate > gray', > 'light slate gray', 'gray', 'light grey'] > > root = Tk() > scrollbar = Scrollbar(root) > scrollbar.pack( side = RIGHT, fill=Y ) > > mylist = Listbox(root, yscrollcommand = scrollbar.set ) > for c in COLORS: > e = Label(mylist, text = c, background = c) > mylist.insert(END,e ) > e.pack(fill=X)#Problem line???? > > mylist.pack( side = LEFT, fill = BOTH ) > scrollbar.config( command = mylist.yview ) > > mainloop() > As you can see I have an interesting line shown as a "Problem line????". > If this line is out I get a list of pairs of number showing the default 10 > lines and the list of numbers is "scrollable". However if the line is in > as shown above, I get a list 26 lines long, with the lovely colours nicely > shown. If I drag the list to a shorter size, the scroll bar appears but > its movement does not link with the list. It goes up an down nicely but > the list stays still. This is rather inconvenient when trying to view the > complete list of colours, which is 479 high! > > Thanks in anticipation of anyone being able to help me, it will be very > much appreciated. > > Cheers, Rob > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Thu Jan 16 14:44:21 2014 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Thu, 16 Jan 2014 14:44:21 +0100 Subject: [Tkinter-discuss] Binding a List to a ScrollBar In-Reply-To: <52D79D60.8010308@rambler.ru> References: <041F3C178A954AD28ABF158B08C03B6E@xdesktop> <52D79D60.8010308@rambler.ru> Message-ID: Hi Rob, Complete solution, with a re-usable ScrolledListBox class, below: from tkinter import * class ScrolledListBox(Frame): def __init__(self, master, items=[], width=24, height=20, bgcol="white", **keywords): Frame.__init__(self, master) self.config(bg=bgcol) # Scrollbars scrollbar = Scrollbar(self, orient=VERTICAL) # Create the listbox self.table=Listbox(self, yscrollcommand=scrollbar.set) self.table.config(bg = bgcol, width=width, height=height) scrollbar.config(command=self.table.yview) scrollbar.pack(side=RIGHT, fill=Y) self.table.pack(side=LEFT, fill=BOTH, expand=1) for kw in keywords: self.table[kw]=keywords[kw] # insert the items for item in items: self.addItem(item) def addItem(self, item, bg=None): self.table.insert(END, item) if bg: self.table.itemconfig(END, background=bg) COLORS =['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace', 'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff', 'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', 'lavender', 'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', 'slate gray', 'light slate gray', 'gray', 'light grey'] root = Tk() sb=ScrolledListBox(root, []) sb.pack(side=LEFT) for c in COLORS: sb.addItem(c, c) root.mainloop() On 16 January 2014 09:50, Nicco Kunzmann wrote: > Hello Rob, > > as far as I remember you can only insert text into a Listbox. > Maybe you pack Widgets onto a Listbox they appear but it does not make > them items. > Try this: > mylist.insert(END,*c* ) > mylist.itemconfigure(END, background = c) > If you want to change the background. > > Greetings, > Nicco > > Am 16.01.2014 07:06, schrieb Rob Ward: > > Hi Folks, > Sorry to be back so soon but I have another challenge. I wanted to choose > some colours for my program and came across a program that claimed to list > the colours in a nifty little Python program. Cute I thought, I must try > that. Quite a few hours later I am stumped. Here is the code with only the > first 26 colours as data - > > from tkinter import * > > COLORS =['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral > white', 'old lace', > 'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', > 'peach puff', > 'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', > 'lavender', > 'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', 'slate > gray', > 'light slate gray', 'gray', 'light grey'] > > root = Tk() > scrollbar = Scrollbar(root) > scrollbar.pack( side = RIGHT, fill=Y ) > > mylist = Listbox(root, yscrollcommand = scrollbar.set ) > for c in COLORS: > e = Label(mylist, text = c, background = c) > mylist.insert(END,e ) > e.pack(fill=X)#Problem line???? > > mylist.pack( side = LEFT, fill = BOTH ) > scrollbar.config( command = mylist.yview ) > > mainloop() > As you can see I have an interesting line shown as a "Problem line????". > If this line is out I get a list of pairs of number showing the default 10 > lines and the list of numbers is "scrollable". However if the line is in > as shown above, I get a list 26 lines long, with the lovely colours nicely > shown. If I drag the list to a shorter size, the scroll bar appears but > its movement does not link with the list. It goes up an down nicely but > the list stays still. This is rather inconvenient when trying to view the > complete list of colours, which is 479 high! > > Thanks in anticipation of anyone being able to help me, it will be very > much appreciated. > > Cheers, Rob > > > > > _______________________________________________ > Tkinter-discuss mailing listTkinter-discuss at python.orghttps://mail.python.org/mailman/listinfo/tkinter-discuss > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From li.beinan at gmail.com Mon Jan 27 05:51:16 2014 From: li.beinan at gmail.com (Beinan Li) Date: Sun, 26 Jan 2014 23:51:16 -0500 Subject: [Tkinter-discuss] Canvas performance, OpenGL, VTK Message-ID: Hi tkinter, I'm investigating into tkinter for data visualization with Python. Seems that the Canvas widget is the one for drawing data curves, and I will need several Canvas at the same time for different views and the same data. Now the question is how is the general graphics performance if I need to update the Canvas frequently, e.g., 30-60fps? If the performance does not meet my expectation, should I consider using OpenGL instead? If yes, I have no idea how to hook GL up with tkinter. There is a tk OpenGL widget, but seems it is not easy to set up: http://stackoverflow.com/questions/11844882/tkinter-opengl-context-in-python So I wonder if there are any documents about how to make Canvas work with OpenGL or VTK. Thanks Beinan -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Tue Jan 28 10:52:12 2014 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 28 Jan 2014 10:52:12 +0100 Subject: [Tkinter-discuss] Strange word wrapping behaviour in Text widget Message-ID: Hi All, Running Python 3.3.3 / Tk 8.5.15 under MacOSX 10.9.1 I am using a Text widget to display some text from a file, with 'wrap=WORD' set. When the file uses both \n and \r in line breaks (which happens in some Windows files) The last word of each line is wrapped to the next line. E.g. text: "Mike Krath\n\ris nice." is displayed as Mike Krath is nice. When editing the text, the widget gets confused as to where characters are on the screen. Clicking just past the end of line of "Krath", the insert curser appears BEFORE the "h". Try the example below to see if it happens on your installation: from tkinter import * tk = Tk() fr=Text(tk, wrap=WORD) fr.pack() fr.insert(END, "Mike Krath\r\nHigh and Lifted Up\r\nIt was a windy day.") tk.mainloop() I could replace all "\n\r" in my text with "\n", but it would be better for Tk to behave as expected. Mick From klappnase at web.de Tue Jan 28 11:15:32 2014 From: klappnase at web.de (Michael Lange) Date: Tue, 28 Jan 2014 11:15:32 +0100 Subject: [Tkinter-discuss] Strange word wrapping behaviour in Text widget In-Reply-To: References: Message-ID: <20140128111532.d140b8830b03242dd6dd8221@web.de> Hi, On Tue, 28 Jan 2014 10:52:12 +0100 "Michael O'Donnell" wrote: > Hi All, > > Running Python 3.3.3 / Tk 8.5.15 under MacOSX 10.9.1 > > I am using a Text widget to display > some text from a file, with 'wrap=WORD' set. > > When the file uses both \n and \r in line breaks > (which happens in some Windows files) > > The last word of each line is wrapped to the next line. > E.g. text: > > "Mike Krath\n\ris nice." is displayed as > > Mike > Krath > > is nice. > > When editing the text, the widget gets confused > as to where characters are on the screen. Clicking > just past the end of line of "Krath", the insert curser > appears BEFORE the "h". > > Try the example below to see if it happens on > your installation: (...) this does not happen here with Python-3.2.3 / Tk-8.5.11 on debian; here the carriage return is displayed as a small rectangle with "CR" in it (better than I had expected ;), editing appears to be fine. Maybe it is a Mac-specific issue? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. There's no honorable way to kill, no gentle way to destroy. There is nothing good in war. Except its ending. -- Abraham Lincoln, "The Savage Curtain", stardate 5906.5 From michael.odonnell at uam.es Tue Jan 28 12:46:53 2014 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 28 Jan 2014 12:46:53 +0100 Subject: [Tkinter-discuss] Strange word wrapping behaviour in Text widget In-Reply-To: <20140128111532.d140b8830b03242dd6dd8221@web.de> References: <20140128111532.d140b8830b03242dd6dd8221@web.de> Message-ID: Thanks Michael, Just checked it with Windows, and no problem, although the current 3.3.4 install uses TK 8.5.11, and my problem was under 8.5.15. But Python 3.4 with Tk 8.6 exhibits no problem also, so maybe a MacOSX problem. mick On 28 January 2014 11:15, Michael Lange wrote: > Hi, > > On Tue, 28 Jan 2014 10:52:12 +0100 > "Michael O'Donnell" wrote: > >> Hi All, >> >> Running Python 3.3.3 / Tk 8.5.15 under MacOSX 10.9.1 >> >> I am using a Text widget to display >> some text from a file, with 'wrap=WORD' set. >> >> When the file uses both \n and \r in line breaks >> (which happens in some Windows files) >> >> The last word of each line is wrapped to the next line. >> E.g. text: >> >> "Mike Krath\n\ris nice." is displayed as >> >> Mike >> Krath >> >> is nice. >> >> When editing the text, the widget gets confused >> as to where characters are on the screen. Clicking >> just past the end of line of "Krath", the insert curser >> appears BEFORE the "h". >> >> Try the example below to see if it happens on >> your installation: > (...) > > this does not happen here with Python-3.2.3 / Tk-8.5.11 on debian; here > the carriage return is displayed as a small rectangle with "CR" in it > (better than I had expected ;), editing appears to be fine. > Maybe it is a Mac-specific issue? > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > There's no honorable way to kill, no gentle way to destroy. There is > nothing good in war. Except its ending. > -- Abraham Lincoln, "The Savage Curtain", stardate 5906.5 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss