From donaldkenney at gmail.com Sun Aug 3 23:34:42 2008 From: donaldkenney at gmail.com (vtcodger) Date: Sun, 3 Aug 2008 14:34:42 -0700 (PDT) Subject: [Tkinter-discuss] Creating a new widget class Message-ID: <18802754.post@talk.nabble.com> I wonder if someone who understands Python and Tkinter a bit better than I could help me out. Basically, I'm trying to encapsulate the kind of messy stuff associated with setting up a listbox with a scrollbar in a Python class. From my probably incredibly naive point of view, it doesn't look too hard. class ScrolledList(Frame,Listbox,Scrollbar) : #At this point we have a template for objects that have all the #attributes and methods of Frames,Listboxes,and Scrollbars. For #names that occur in all, the Frame version takes precedence over #the Listbox version and that in turn takes precedence over #Scrollbar version def __init__ (self, Tkobject, height=4, width=50) : #This code is executed whenever a new scrolled list object is #created (instantiated) self.f = Frame(Tkobject) s = Scrollbar(self.f,orient=VERTICAL) self.l = Listbox(self.f, height=height, width=width, yscrollcommand=s.set, exportselection=0) #We have now created a frame, scrollbar and listbox s.config(command=self.l.yview) s.pack(side=RIGHT, fill=Y); self.l.pack() #And configured the listbox and scrollbar to interact And it creates a Tkinter object with a gazillion attributes. Unfortunately tk isn't one of them. When I try to invoke the methods, I am informed that the new object has no 'tk' attribute. That's correct. It doesn't. Apparently I have failed to call some necessary constructor. But which? Maybe I'm close to having it right because if I create a grid attribute in the class and pass the parameters to the frame grid method, the scrolled listbox can be configured and displayed. def grid(self,row=90,column=1,rowspan=5,columnspan=4,sticky=W) : self.f.grid(row=row,column=column,rowspan=rowspan,columnspan=columnspan,sticky=sticky) What am I doing wrong, or not doing right? -- View this message in context: http://www.nabble.com/Creating-a-new-widget-class-tp18802754p18802754.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From peter.milliken at gmail.com Tue Aug 5 23:42:24 2008 From: peter.milliken at gmail.com (Peter Milliken) Date: Wed, 6 Aug 2008 07:42:24 +1000 Subject: [Tkinter-discuss] Creating a new widget class In-Reply-To: <18802754.post@talk.nabble.com> References: <18802754.post@talk.nabble.com> Message-ID: <791153ba0808051442k6688df82ka5b2a9e77fc4b75@mail.gmail.com> I won't answer the original question - sorry, no time to look at the code :-) But why roll your own? There is a PMW widget called ScrolledListBox that probably does all that you require. I would highly recommend the PMW distribution - it is exceptionally well thought out and (IMO :-)) brilliantly executed. You can find it through any of the Python resource pages or by Googling "Python PMW". It has been around (and exceptionally stable) for a number of years now - it is at v1.2. I have been using it for close to 8 years and it has only been up rev'd once in that time. It forms an excellent framework for creating your own composite widgets as well. There is a bit of a learning curve to achieve that part (using ScrolledListBox is easy) but once you get your head around the philosophy of the package it is fantastically powerful. So have a look at PMW - I can't recommend it enough :-) Peter On Mon, Aug 4, 2008 at 7:34 AM, vtcodger wrote: > > I wonder if someone who understands Python and Tkinter a bit better than I > could help me out. Basically, I'm trying to encapsulate the kind of messy > stuff associated with setting up a listbox with a scrollbar in a Python > class. From my probably incredibly naive point of view, it doesn't look > too > hard. > > class ScrolledList(Frame,Listbox,Scrollbar) : > #At this point we have a template for objects that have all the > #attributes and methods of Frames,Listboxes,and Scrollbars. For > #names that occur in all, the Frame version takes precedence over > #the Listbox version and that in turn takes precedence over > #Scrollbar version > > def __init__ (self, Tkobject, height=4, width=50) : > #This code is executed whenever a new scrolled list object is > #created (instantiated) > self.f = Frame(Tkobject) > s = Scrollbar(self.f,orient=VERTICAL) > self.l = Listbox(self.f, height=height, width=width, > yscrollcommand=s.set, exportselection=0) > #We have now created a frame, scrollbar and listbox > > s.config(command=self.l.yview) > s.pack(side=RIGHT, fill=Y); self.l.pack() > #And configured the listbox and scrollbar to interact > > And it creates a Tkinter object with a gazillion attributes. Unfortunately > tk isn't one of them. When I try to invoke the methods, I am informed that > the new object has no 'tk' attribute. That's correct. It doesn't. > Apparently I have failed to call some necessary constructor. But which? > > Maybe I'm close to having it right because if I create a grid attribute in > the class and pass the parameters to the frame grid method, the scrolled > listbox can be configured and displayed. > > def grid(self,row=90,column=1,rowspan=5,columnspan=4,sticky=W) : > > > self.f.grid(row=row,column=column,rowspan=rowspan,columnspan=columnspan,sticky=sticky) > > What am I doing wrong, or not doing right? > -- > View this message in context: > http://www.nabble.com/Creating-a-new-widget-class-tp18802754p18802754.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > 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 ron.longo at cox.net Tue Aug 5 23:45:16 2008 From: ron.longo at cox.net (Ron Longo) Date: Tue, 5 Aug 2008 17:45:16 -0400 Subject: [Tkinter-discuss] Creating a new widget class In-Reply-To: <18802754.post@talk.nabble.com> References: <18802754.post@talk.nabble.com> Message-ID: There are two ways to create your own widgets with Tkinter: subclass from an existing widget or construct your new widget in a Frame. Subclassing from a Frame is the more general method. Subclassing an existing widget is usually only useful if you are creating a specialized version of an existing widget. If your widget is a composite of two or more existing widgets (often called a megawidget), you should almost always use the Frame approach. Alternatively you can use a widget-building framework such as PMW. Here's how to get started: In your constructor you first initialize the superclass then create your childwidgets. The parent of the subwidgets is self. class ScrolledList( Tkinter.Frame ): def __init__( self, parent, **options ): Tkinter.Frame.__init__( self, parent, **options ) self._list = Tkinter.List( self ) self._scrollbar = Tkinter.Scrollbar( self ) self._list.pack( side=Tkinter.LEFT ) self._scrollbar.pack( side=Tkinter.LEFT ) This allows your widget to behave like any other widget. That is to use your widget, you construct it: myWidgetInstance = ScrolledList( aParentWidget, ... ) Then you pack, grid or place it to display it. myWidgetInstance.pack( ) If you want to allow your widget to handle its own custom widget options, you need to pull these options out of the **options argument before calling Tkinter.Frame.__init__( ... ). If you don't like the .pack() methods being in __init__, you could override pack(), grid() and place() and pack the list and scrollbar there instead. Hope this helps ----- Original Message ----- From: "vtcodger" To: Sent: Sunday, August 03, 2008 5:34 PM Subject: [Tkinter-discuss] Creating a new widget class > > I wonder if someone who understands Python and Tkinter a bit better than I > could help me out. Basically, I'm trying to encapsulate the kind of messy > stuff associated with setting up a listbox with a scrollbar in a Python > class. From my probably incredibly naive point of view, it doesn't look > too > hard. > > class ScrolledList(Frame,Listbox,Scrollbar) : > #At this point we have a template for objects that have all the > #attributes and methods of Frames,Listboxes,and Scrollbars. For > #names that occur in all, the Frame version takes precedence over > #the Listbox version and that in turn takes precedence over > #Scrollbar version > > def __init__ (self, Tkobject, height=4, width=50) : > #This code is executed whenever a new scrolled list object is > #created (instantiated) > self.f = Frame(Tkobject) > s = Scrollbar(self.f,orient=VERTICAL) > self.l = Listbox(self.f, height=height, width=width, > yscrollcommand=s.set, exportselection=0) > #We have now created a frame, scrollbar and listbox > > s.config(command=self.l.yview) > s.pack(side=RIGHT, fill=Y); self.l.pack() > #And configured the listbox and scrollbar to interact > > And it creates a Tkinter object with a gazillion attributes. > Unfortunately > tk isn't one of them. When I try to invoke the methods, I am informed > that > the new object has no 'tk' attribute. That's correct. It doesn't. > Apparently I have failed to call some necessary constructor. But which? > > Maybe I'm close to having it right because if I create a grid attribute in > the class and pass the parameters to the frame grid method, the scrolled > listbox can be configured and displayed. > > def grid(self,row=90,column=1,rowspan=5,columnspan=4,sticky=W) : > > self.f.grid(row=row,column=column,rowspan=rowspan,columnspan=columnspan,sticky=sticky) > > What am I doing wrong, or not doing right? > -- > View this message in context: > http://www.nabble.com/Creating-a-new-widget-class-tp18802754p18802754.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss From donaldkenney at gmail.com Wed Aug 6 10:23:34 2008 From: donaldkenney at gmail.com (vtcodger) Date: Wed, 6 Aug 2008 01:23:34 -0700 (PDT) Subject: [Tkinter-discuss] Creating a new widget class In-Reply-To: <18802754.post@talk.nabble.com> References: <18802754.post@talk.nabble.com> Message-ID: <18846448.post@talk.nabble.com> Ron -- Thanks, I thought I was doing about what you describe, but apparently not as the tk attribute for the class objects is not getting set up. I'm a bit hazy on what the tk attribute does (other than making things work) and can't find much about it via Google. I'll go back and subclass from frame rather than trying to multiply inherit from Frame, List, and Scrollbar. Peter -- Thanks also. I was aware of the PMW scrolledlist. And it works fine. But I don't want to use any components that are not part of the standard Python distribution. Should have mentioned that, but the post was getting overlong. === As a practical matter, I discovered after I posted, that I can access my frame, list (and probably scrollbar as well) methods from the main program via their objects. That is to say that the way I did it, a scrolled list object sl doesn't have a directly usable grid or insert method, but sl.f.grid(... or sl.l.insert seem to work fine. What bothers me, isn't that I can't get things to work. It's that I clearly don't understand what is going on. -- View this message in context: http://www.nabble.com/Creating-a-new-widget-class-tp18802754p18846448.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From brauliomhorta at gmail.com Wed Aug 6 14:06:40 2008 From: brauliomhorta at gmail.com (=?ISO-8859-1?Q?Br=E1ulio_Marques_Horta?=) Date: Wed, 6 Aug 2008 09:06:40 -0300 Subject: [Tkinter-discuss] Hide Button on taskbar Message-ID: Hi, I just started using Tkinter in windows, and I was wondering if it is possible to hide the button from tk window that appears in the taskbar while still showing this window. I couldn't find any clue. All I could do was hide everything (button + window). Thanks! Br?ulio From peter.milliken at gmail.com Thu Aug 7 06:05:36 2008 From: peter.milliken at gmail.com (Peter Milliken) Date: Thu, 7 Aug 2008 14:05:36 +1000 Subject: [Tkinter-discuss] Creating a new widget class In-Reply-To: <18846448.post@talk.nabble.com> References: <18802754.post@talk.nabble.com> <18846448.post@talk.nabble.com> Message-ID: <791153ba0808062105t7493526ao53e2a446def4e65a@mail.gmail.com> Well, here are some clues - the "multiple" inheritance doesn't seem to work the way the manual *implies* it should i.e. multiple inheritance is described as searching for methods in the first inheritance and then all it's ancestors, then onto the next and all its ancestors and so on. To get an "insert" (Listbox) method on your class you need to invoke the __init__ method on the super classes (sub-classes should always invoke the initialisation of their super class anyway - so that is something your class definition is definitely missing!) i.e. Listbox.__init__(self) If you do just this, then ScrolledList has the Listbox attributes (and none of the others). If you then add initialisation of Scrollbar then you have this: Listbox.__init__(self) Scrollbar.__init__(self) And viola! ScrolledList now has the methods of Scrollbar - and "lost" the methods of Listbox. So without being any kind of expert on Tk objects with inheritance etc it looks very much as though you have attempted too simplistic an approach to creating what amounts to a "composite" object. I would suggest that you pick one of your 3 objects to do the real inheritance - and then create actual methods on ScrolledList that "duplicate" the methods of the other object methods. That is the only way I can see you get this working at the moment. Hope this helps Peter On Wed, Aug 6, 2008 at 6:23 PM, vtcodger wrote: > > Ron -- Thanks, I thought I was doing about what you describe, but > apparently > not as the tk attribute for the class objects is not getting set up. I'm a > bit hazy on what the tk attribute does (other than making things work) and > can't find much about it via Google. I'll go back and subclass from frame > rather than trying to multiply inherit from Frame, List, and Scrollbar. > > Peter -- Thanks also. I was aware of the PMW scrolledlist. And it works > fine. But I don't want to use any components that are not part of the > standard Python distribution. Should have mentioned that, but the post was > getting overlong. > > === > > As a practical matter, I discovered after I posted, that I can access my > frame, list (and probably scrollbar as well) methods from the main program > via their objects. That is to say that the way I did it, a scrolled list > object sl doesn't have a directly usable grid or insert method, but > sl.f.grid(... or sl.l.insert seem to work fine. > > What bothers me, isn't that I can't get things to work. It's that I > clearly > don't understand what is going on. > -- > View this message in context: > http://www.nabble.com/Creating-a-new-widget-class-tp18802754p18846448.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > 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 alexnbryan at gmail.com Mon Aug 11 17:35:21 2008 From: alexnbryan at gmail.com (Alexnb) Date: Mon, 11 Aug 2008 08:35:21 -0700 (PDT) Subject: [Tkinter-discuss] simple way of clearing out a text widget Message-ID: <18928171.post@talk.nabble.com> I am wondering, what is the best way to clear out a text widget. If it matters, I will still want to use that text widget again. -- View this message in context: http://www.nabble.com/simple-way-of-clearing-out-a-text-widget-tp18928171p18928171.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From Cameron at phaseit.net Mon Aug 11 18:03:14 2008 From: Cameron at phaseit.net (Cameron Laird) Date: Mon, 11 Aug 2008 16:03:14 +0000 Subject: [Tkinter-discuss] simple way of clearing out a text widget In-Reply-To: <18928171.post@talk.nabble.com> References: <18928171.post@talk.nabble.com> Message-ID: <20080811160314.GA18132@lairds.us> On Mon, Aug 11, 2008 at 08:35:21AM -0700, Alexnb wrote: . . . > I am wondering, what is the best way to clear out a text widget. If it > matters, I will still want to use that text widget again. . . . text.delete(1.0, END) From msa01 at bitflipper.ca Mon Aug 11 17:54:42 2008 From: msa01 at bitflipper.ca (Cam Farnell) Date: Mon, 11 Aug 2008 12:54:42 -0300 Subject: [Tkinter-discuss] simple way of clearing out a text widget In-Reply-To: <18928171.post@talk.nabble.com> References: <18928171.post@talk.nabble.com> Message-ID: <48A060C2.8060503@bitflipper.ca> Well one of the best ways is to read the manual first. Some quite reasonable TkInter documentation is available here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/ You might look for documentation on the Text widget and then "Methods on Text widgets". The Text widget is pretty good at dealing with text; I'm sure there will be some way of getting rid of unwanted text. Cam Alexnb wrote: > I am wondering, what is the best way to clear out a text widget. If it > matters, I will still want to use that text widget again. From alexnbryan at gmail.com Tue Aug 12 18:39:16 2008 From: alexnbryan at gmail.com (Alexnb) Date: Tue, 12 Aug 2008 09:39:16 -0700 (PDT) Subject: [Tkinter-discuss] putting a series of hyperlinks in a text widget Message-ID: <18948087.post@talk.nabble.com> I am having trouble figuring out the best way to do this and would love some help. What I need to do is to create clickable links in a text widget, but there will be at max 40. They will all be different. I am wondering what is the best way to create a clickable unique url in a text widget. I know that you can bind tags, but the problem with that is since each url is unique that would mean 40 tags to get what I want... at least, as far as I know, there might be a way to do it that I just don't know. Sorry if I am being vague, I just don't know what else to say. If you need any extra info just reply I would be happy to provide. -- View this message in context: http://www.nabble.com/putting-a-series-of-hyperlinks-in-a-text-widget-tp18948087p18948087.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From fred.mailhot at gmail.com Wed Aug 13 03:18:48 2008 From: fred.mailhot at gmail.com (Fred Mailhot) Date: Tue, 12 Aug 2008 21:18:48 -0400 Subject: [Tkinter-discuss] Unicode on Mac (yet again) Message-ID: Greetings, I've followed some of the discussion on the list concerning the problem of getting some Unicode characters to display properly. As suggested in a few messages, I've recompiled my python to link to Tcl/Tk8.5. I know this has succeeded, as running Tkinter._test() pops up a dialog confirming that I'm using 8.5. Unfortunately, there still seem to be problems displaying Unicode characters properly. The following snippet demonstrates (disclaimer: I'm not a Tkinter guru by any means)... import Tkinter root = Tkinter.Tk() w1 = Tkinter.Button(root, text=u"\u026E", font=("Lucida Grande",24)) w2 = Tkinter.Label(root, text=u"\u026E", font=("Lucida Grande",24)) w1.pack() w2.pack The Button displays the correct character (a digraph from the International Phonetic Alphabet), whereas the Label displays what looks like a Chinese kanji character...the same problem as in 8.4. Is there something I'm doing wrong? For the record, I'm running OSX 10.4.11 on a PPC Mac. Thanks for any advice or pointers, Fred. From fredrik at pythonware.com Wed Aug 13 11:07:45 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Aug 2008 11:07:45 +0200 Subject: [Tkinter-discuss] Creating a new widget class In-Reply-To: <791153ba0808062105t7493526ao53e2a446def4e65a@mail.gmail.com> References: <18802754.post@talk.nabble.com> <18846448.post@talk.nabble.com> <791153ba0808062105t7493526ao53e2a446def4e65a@mail.gmail.com> Message-ID: Peter Milliken wrote: > Well, here are some clues - the "multiple" inheritance doesn't seem to > work the way the manual *implies* it should i.e. multiple inheritance is > described as searching for methods in the first inheritance and then all > it's ancestors, then onto the next and all its ancestors and so on. Tkinter widget instances are proxy objects that delegate method calls to an underlying Tk widget. A widget instance can only be bound to a single Tk widget. Multiple inheritance works as usual at the Tkinter class level, but that doesn't help if the widget instance is not bound to the right Tk object when you do a method call. > To get an "insert" (Listbox) method on your class you need to invoke the > __init__ method on the super classes (sub-classes should always invoke > the initialisation of their super class anyway - so that is something > your class definition is definitely missing!) i.e. > > Listbox.__init__(self) That binds the widget to the underlying Tk listbox widget (see the code in Tkinter's BaseWidget for details). After this call, any method calls will be forwarded to the Tk listbox. > Listbox.__init__(self) > Scrollbar.__init__(self) > > And viola! ScrolledList now has the methods of Scrollbar - and "lost" > the methods of Listbox. After those calls, the widget instance ends up being bound to a Tk scrollbar widget. There's no change in what methods the object has at the Python level, though. From iain at day-online.org.uk.invalid Thu Aug 14 22:19:10 2008 From: iain at day-online.org.uk.invalid (Iain Day) Date: Thu, 14 Aug 2008 21:19:10 +0100 Subject: [Tkinter-discuss] initial state of radiobutton Message-ID: Hi, I'm trying to create a preferences dialog. At the moment, I'm just reading a config file using ConfigParser and displaying this in a tkSimpleDialog. I've got some Entry widgets working okay, but I can't get the radiobuttons to work. The code is: import Tkinter as tk settings = tk.LabelFrame(master, text="Settings") settings.grid(row=0, column=0) tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, sticky=tk.E) angles = tk.StringVar(value=__main__.angles) tk.Radiobutton(settings, text="Degrees", variable=angles, value='degrees').grid(row=0, column=1) tk.Radiobutton(settings, text="Radians", variable=angles, value='radians').grid(row=0, column=2) When I run this, angles is set to degrees but I don't get the radiobutton active (either of them). What am I doing wrong? Thanks, Iain From peter.milliken at gmail.com Thu Aug 14 23:36:40 2008 From: peter.milliken at gmail.com (Peter Milliken) Date: Fri, 15 Aug 2008 07:36:40 +1000 Subject: [Tkinter-discuss] Creating a new widget class In-Reply-To: References: <18802754.post@talk.nabble.com> <18846448.post@talk.nabble.com> <791153ba0808062105t7493526ao53e2a446def4e65a@mail.gmail.com> Message-ID: <791153ba0808141436y7cce82afi1c330000907427f0@mail.gmail.com> Hi Fred, Yeah, this question hit my "curiousity bump" and I have been "investigating" it on and off - as time allows :-) I "discovered" what you have detailed - the last Tk object "bound" is the one that tries to interpret the call (via self._w) - and if that happened to be the Scrollbar then the Listbox methods become "lost" for want of a better term - and vice versa. I then started to look at "intercepting" the unsuccessful call i.e. before the exception is raised, to see if I could potentially "re-route" the request at run-time - but couldn't work out how to do that, I suspect you can't? Peter On Wed, Aug 13, 2008 at 7:07 PM, Fredrik Lundh wrote: > Peter Milliken wrote: > > Well, here are some clues - the "multiple" inheritance doesn't seem to >> work the way the manual *implies* it should i.e. multiple inheritance is >> described as searching for methods in the first inheritance and then all >> it's ancestors, then onto the next and all its ancestors and so on. >> > > Tkinter widget instances are proxy objects that delegate method calls to an > underlying Tk widget. A widget instance can only be bound to a single Tk > widget. > > Multiple inheritance works as usual at the Tkinter class level, but that > doesn't help if the widget instance is not bound to the right Tk object when > you do a method call. > > To get an "insert" (Listbox) method on your class you need to invoke the >> __init__ method on the super classes (sub-classes should always invoke the >> initialisation of their super class anyway - so that is something your class >> definition is definitely missing!) i.e. >> >> Listbox.__init__(self) >> > > That binds the widget to the underlying Tk listbox widget (see the code in > Tkinter's BaseWidget for details). After this call, any method calls will > be forwarded to the Tk listbox. > > > Listbox.__init__(self) > > Scrollbar.__init__(self) > > > > And viola! ScrolledList now has the methods of Scrollbar - and "lost" > > the methods of Listbox. > > After those calls, the widget instance ends up being bound to a Tk > scrollbar widget. There's no change in what methods the object has at the > Python level, though. > > > > > _______________________________________________ > 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 michael.odonnell at uam.es Fri Aug 15 01:38:48 2008 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Fri, 15 Aug 2008 09:38:48 +1000 Subject: [Tkinter-discuss] initial state of radiobutton In-Reply-To: References: Message-ID: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> Dear Iain, Makes it easier to test your code if you provide a standalone example. I modified your code as follows to get it to run: import Tkinter as tk master = tk.Tk() settings = tk.LabelFrame(master, text="Settings") settings.grid(row=0, column=0) tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, sticky=tk.E) angles = tk.StringVar(value='radians') tk.Radiobutton(settings, text="Degrees", variable=angles, value='degrees').grid(row=0, column=1) tk.Radiobutton(settings, text="Radians", variable=angles, value='radians').grid(row=0, column=2) master.mainloop() ...and on my Macosx running python 2.5.2 it runs fine, with buttons selected. My bet is that angles is not in fact set, or is not set to one of 'degrees' or 'radians'. Put a print statement to see what value __main__.angles has at the point of setting the variable angles. Mick On Fri, Aug 15, 2008 at 6:19 AM, Iain Day wrote: > Hi, > > I'm trying to create a preferences dialog. At the moment, I'm just reading a > config file using ConfigParser and displaying this in a tkSimpleDialog. > > I've got some Entry widgets working okay, but I can't get the radiobuttons > to work. The code is: > > import Tkinter as tk > > settings = tk.LabelFrame(master, text="Settings") > settings.grid(row=0, column=0) > > tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, > sticky=tk.E) > > angles = tk.StringVar(value=__main__.angles) > > tk.Radiobutton(settings, text="Degrees", variable=angles, > value='degrees').grid(row=0, column=1) > > tk.Radiobutton(settings, text="Radians", variable=angles, > value='radians').grid(row=0, column=2) > > When I run this, angles is set to degrees but I don't get the radiobutton > active (either of them). > > What am I doing wrong? > > Thanks, > > Iain > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From iain at day-online.org.uk.invalid Sat Aug 16 13:34:23 2008 From: iain at day-online.org.uk.invalid (Iain Day) Date: Sat, 16 Aug 2008 12:34:23 +0100 Subject: [Tkinter-discuss] initial state of radiobutton In-Reply-To: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> References: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> Message-ID: Hi Mick, Sorry about that. The code below does work, however, in my case its a little more complex. I'll try and explain. I've put most of the code into different modules which get imported in the usual way, so I have one that has all the classes for the menu bar. There is also a class in here which generates the tkSimpleDialog for the preferences. Is is here that I've got the bit of code I posted below. __main__.angles is set correctly, and if I do: print tk.StringVar.get(angles) I get the correct result. I'm a little confused. Also if I put angles into an Entry widget it is correct. Thanks for your help, Iain Michael O'Donnell wrote: > Dear Iain, > > Makes it easier to test your code if you provide > a standalone example. > > I modified your code as follows to get it to run: > > import Tkinter as tk > master = tk.Tk() > settings = tk.LabelFrame(master, text="Settings") > settings.grid(row=0, column=0) > tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, sticky=tk.E) > angles = tk.StringVar(value='radians') > tk.Radiobutton(settings, text="Degrees", variable=angles, > value='degrees').grid(row=0, column=1) > tk.Radiobutton(settings, text="Radians", variable=angles, > value='radians').grid(row=0, column=2) > master.mainloop() > > ...and on my Macosx running python 2.5.2 it runs fine, with buttons selected. > > My bet is that angles is not in fact set, or is not set > to one of 'degrees' or 'radians'. Put a print statement to > see what value __main__.angles has at the point of > setting the variable angles. > > Mick > > > > On Fri, Aug 15, 2008 at 6:19 AM, Iain Day > wrote: >> Hi, >> >> I'm trying to create a preferences dialog. At the moment, I'm just reading a >> config file using ConfigParser and displaying this in a tkSimpleDialog. >> >> I've got some Entry widgets working okay, but I can't get the radiobuttons >> to work. The code is: >> >> import Tkinter as tk >> >> settings = tk.LabelFrame(master, text="Settings") >> settings.grid(row=0, column=0) >> >> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, >> sticky=tk.E) >> >> angles = tk.StringVar(value=__main__.angles) >> >> tk.Radiobutton(settings, text="Degrees", variable=angles, >> value='degrees').grid(row=0, column=1) >> >> tk.Radiobutton(settings, text="Radians", variable=angles, >> value='radians').grid(row=0, column=2) >> >> When I run this, angles is set to degrees but I don't get the radiobutton >> active (either of them). >> >> What am I doing wrong? >> >> Thanks, >> >> Iain >> >> _______________________________________________ >> Tkinter-discuss mailing list >> Tkinter-discuss at python.org >> http://mail.python.org/mailman/listinfo/tkinter-discuss >> From michael.odonnell at uam.es Sun Aug 17 06:05:56 2008 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sun, 17 Aug 2008 14:05:56 +1000 Subject: [Tkinter-discuss] initial state of radiobutton In-Reply-To: References: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> Message-ID: <47e491110808162105q67e6ef90wf17148678c33111e@mail.gmail.com> Hi Iain, My earlier reply established that the radio widget IS functioning correctly on your machine in the usual case. If there is still something wrong, I'd have to see runnable code from your app which fails to set the radio. Can you make a minimal case which uses the class structure you discuss, and still doesn't work, and send it (probably as a compressed archive, e.g., zip file). I'll then see if I can find the bug. What OS are you on? Mick On Sat, Aug 16, 2008 at 9:34 PM, Iain Day wrote: > Hi Mick, > > Sorry about that. The code below does work, however, in my case its a little > more complex. I'll try and explain. I've put most of the code into different > modules which get imported in the usual way, so I have one that has all the > classes for the menu bar. There is also a class in here which generates the > tkSimpleDialog for the preferences. Is is here that I've got the bit of code > I posted below. > > __main__.angles is set correctly, and if I do: > > print tk.StringVar.get(angles) > > I get the correct result. > > I'm a little confused. Also if I put angles into an Entry widget it is > correct. > > Thanks for your help, > > Iain > > Michael O'Donnell wrote: >> >> Dear Iain, >> >> Makes it easier to test your code if you provide >> a standalone example. >> >> I modified your code as follows to get it to run: >> >> import Tkinter as tk >> master = tk.Tk() >> settings = tk.LabelFrame(master, text="Settings") >> settings.grid(row=0, column=0) >> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, >> sticky=tk.E) >> angles = tk.StringVar(value='radians') >> tk.Radiobutton(settings, text="Degrees", variable=angles, >> value='degrees').grid(row=0, column=1) >> tk.Radiobutton(settings, text="Radians", variable=angles, >> value='radians').grid(row=0, column=2) >> master.mainloop() >> >> ...and on my Macosx running python 2.5.2 it runs fine, with buttons >> selected. >> >> My bet is that angles is not in fact set, or is not set >> to one of 'degrees' or 'radians'. Put a print statement to >> see what value __main__.angles has at the point of >> setting the variable angles. >> >> Mick >> >> >> >> On Fri, Aug 15, 2008 at 6:19 AM, Iain Day >> wrote: >>> >>> Hi, >>> >>> I'm trying to create a preferences dialog. At the moment, I'm just >>> reading a >>> config file using ConfigParser and displaying this in a tkSimpleDialog. >>> >>> I've got some Entry widgets working okay, but I can't get the >>> radiobuttons >>> to work. The code is: >>> >>> import Tkinter as tk >>> >>> settings = tk.LabelFrame(master, text="Settings") >>> settings.grid(row=0, column=0) >>> >>> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, >>> sticky=tk.E) >>> >>> angles = tk.StringVar(value=__main__.angles) >>> >>> tk.Radiobutton(settings, text="Degrees", variable=angles, >>> value='degrees').grid(row=0, column=1) >>> >>> tk.Radiobutton(settings, text="Radians", variable=angles, >>> value='radians').grid(row=0, column=2) >>> >>> When I run this, angles is set to degrees but I don't get the radiobutton >>> active (either of them). >>> >>> What am I doing wrong? >>> >>> Thanks, >>> >>> Iain >>> >>> _______________________________________________ >>> Tkinter-discuss mailing list >>> Tkinter-discuss at python.org >>> http://mail.python.org/mailman/listinfo/tkinter-discuss >>> > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From michael.odonnell at uam.es Sun Aug 17 06:46:14 2008 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sun, 17 Aug 2008 14:46:14 +1000 Subject: [Tkinter-discuss] putting a series of hyperlinks in a text widget In-Reply-To: <18948087.post@talk.nabble.com> References: <18948087.post@talk.nabble.com> Message-ID: <47e491110808162146x50f4b167h95c7dcd0c041664f@mail.gmail.com> Dear Alex, I think you are on to a valid solution: tag each anchor. I would use 2 tags: 1) A general tag called for example 'link', which you config a) to present itself as a link (e.g., in blue, underlines) b) to respond to events, e.g., ButtonRelease 2) a tag for each individual link, which could be an integer indicating which link it is (e.g., the position of the url in a list of urls). When you insert the text of the anchor in the widget, specify: ('link', str(i)) The action bound to the ButtonRelease event can recover which link was pressed, and recover the appropriate url to follow. E.g. from Tkinter import * master = Tk() LINKS=("http://www.python.org", "http://www.heaven.com") def showLink(event): idx= int(event.widget.tag_names(CURRENT)[1]) print LINKS[idx] txt=Text(master) txt.pack(expand=True, fill="both") txt.insert(END, "Press ") txt.insert(END, "here ", ('link', str(0))) txt.insert(END, "for Python. Press ") txt.insert(END, "here ", ('link', str(1))) txt.insert(END, "for Heaven.") txt.tag_config('link', foreground="blue") txt.tag_bind('link', '', showLink) master.mainloop() On Wed, Aug 13, 2008 at 2:39 AM, Alexnb wrote: > > I am having trouble figuring out the best way to do this and would love some > help. > > What I need to do is to create clickable links in a text widget, but there > will be at max 40. They will all be different. I am wondering what is the > best way to create a clickable unique url in a text widget. I know that you > can bind tags, but the problem with that is since each url is unique that > would mean 40 tags to get what I want... at least, as far as I know, there > might be a way to do it that I just don't know. > > Sorry if I am being vague, I just don't know what else to say. If you need > any extra info just reply I would be happy to provide. > -- > View this message in context: http://www.nabble.com/putting-a-series-of-hyperlinks-in-a-text-widget-tp18948087p18948087.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From alexnbryan at gmail.com Sun Aug 17 07:11:34 2008 From: alexnbryan at gmail.com (Alexnb) Date: Sat, 16 Aug 2008 22:11:34 -0700 (PDT) Subject: [Tkinter-discuss] putting a series of hyperlinks in a text widget In-Reply-To: <47e491110808162146x50f4b167h95c7dcd0c041664f@mail.gmail.com> References: <18948087.post@talk.nabble.com> <47e491110808162146x50f4b167h95c7dcd0c041664f@mail.gmail.com> Message-ID: <19017586.post@talk.nabble.com> You know, I think this is exactly what I was looking for. Thanks for your help! Mick O'Donnell wrote: > > Dear Alex, > > I think you are on to a valid solution: tag each anchor. > > I would use 2 tags: > > 1) A general tag called for example 'link', which you config > a) to present itself as a link (e.g., in blue, underlines) > b) to respond to events, e.g., ButtonRelease > > 2) a tag for each individual link, which could be an integer > indicating which link it is (e.g., the position of the url in a list > of urls). > > When you insert the text of the anchor in the widget, specify: ('link', > str(i)) > > The action bound to the ButtonRelease event can recover which link was > pressed, > and recover the appropriate url to follow. > > E.g. > > from Tkinter import * > master = Tk() > > LINKS=("http://www.python.org", "http://www.heaven.com") > > def showLink(event): > idx= int(event.widget.tag_names(CURRENT)[1]) > print LINKS[idx] > > txt=Text(master) > txt.pack(expand=True, fill="both") > txt.insert(END, "Press ") > txt.insert(END, "here ", ('link', str(0))) > txt.insert(END, "for Python. Press ") > txt.insert(END, "here ", ('link', str(1))) > txt.insert(END, "for Heaven.") > txt.tag_config('link', foreground="blue") > txt.tag_bind('link', '', showLink) > > master.mainloop() > > > > On Wed, Aug 13, 2008 at 2:39 AM, Alexnb wrote: >> >> I am having trouble figuring out the best way to do this and would love >> some >> help. >> >> What I need to do is to create clickable links in a text widget, but >> there >> will be at max 40. They will all be different. I am wondering what is the >> best way to create a clickable unique url in a text widget. I know that >> you >> can bind tags, but the problem with that is since each url is unique that >> would mean 40 tags to get what I want... at least, as far as I know, >> there >> might be a way to do it that I just don't know. >> >> Sorry if I am being vague, I just don't know what else to say. If you >> need >> any extra info just reply I would be happy to provide. >> -- >> View this message in context: >> http://www.nabble.com/putting-a-series-of-hyperlinks-in-a-text-widget-tp18948087p18948087.html >> Sent from the Python - tkinter-discuss mailing list archive at >> Nabble.com. >> >> _______________________________________________ >> Tkinter-discuss mailing list >> Tkinter-discuss at python.org >> http://mail.python.org/mailman/listinfo/tkinter-discuss >> > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- View this message in context: http://www.nabble.com/putting-a-series-of-hyperlinks-in-a-text-widget-tp18948087p19017586.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From fredrik at pythonware.com Sun Aug 17 09:05:14 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Aug 2008 09:05:14 +0200 Subject: [Tkinter-discuss] putting a series of hyperlinks in a text widget In-Reply-To: <19017586.post@talk.nabble.com> References: <18948087.post@talk.nabble.com> <47e491110808162146x50f4b167h95c7dcd0c041664f@mail.gmail.com> <19017586.post@talk.nabble.com> Message-ID: Alexnb wrote: > You know, I think this is exactly what I was looking for. > > Thanks for your help! Here's the first hit for "tkinter hyperlink", btw: http://effbot.org/zone/tkinter-text-hyperlink.htm From iain at day-online.org.uk.invalid Sun Aug 17 14:02:58 2008 From: iain at day-online.org.uk.invalid (Iain Day) Date: Sun, 17 Aug 2008 13:02:58 +0100 Subject: [Tkinter-discuss] initial state of radiobutton In-Reply-To: <47e491110808162105q67e6ef90wf17148678c33111e@mail.gmail.com> References: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> <47e491110808162105q67e6ef90wf17148678c33111e@mail.gmail.com> Message-ID: Hi Mick, Sorry about that. Here is the simplest example, which fails: import Tkinter as tk import tkSimpleDialog def edit_preferences(event=None): prefs = Preferences(master, title="Preferences") class Preferences(tkSimpleDialog.Dialog): def body(self, master): settings = tk.LabelFrame(master, text="Settings") settings.grid(row=0, column=0) tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, sticky=tk.E) angles = tk.StringVar(value='radians') tk.Radiobutton(settings, text="Degrees", variable=angles,value='degrees').grid(row=0, column=1) tk.Radiobutton(settings, text="Radians", variable=angles,value='radians').grid(row=0, column=2) master = tk.Tk() tk.Button(master, text="Prefs", command=edit_preferences).grid() master.mainloop() Thanks for your help, Iain Michael O'Donnell wrote: > Hi Iain, > > My earlier reply established that the radio widget IS functioning correctly > on your machine in the usual case. If there is still something wrong, I'd have > to see runnable code from your app which fails to set the radio. Can you > make a minimal case which uses the class structure you discuss, and > still doesn't work, and send it (probably as a compressed archive, > e.g., zip file). > > I'll then see if I can find the bug. What OS are you on? > > Mick > > On Sat, Aug 16, 2008 at 9:34 PM, Iain Day > wrote: >> Hi Mick, >> >> Sorry about that. The code below does work, however, in my case its a little >> more complex. I'll try and explain. I've put most of the code into different >> modules which get imported in the usual way, so I have one that has all the >> classes for the menu bar. There is also a class in here which generates the >> tkSimpleDialog for the preferences. Is is here that I've got the bit of code >> I posted below. >> >> __main__.angles is set correctly, and if I do: >> >> print tk.StringVar.get(angles) >> >> I get the correct result. >> >> I'm a little confused. Also if I put angles into an Entry widget it is >> correct. >> >> Thanks for your help, >> >> Iain >> >> Michael O'Donnell wrote: >>> Dear Iain, >>> >>> Makes it easier to test your code if you provide >>> a standalone example. >>> >>> I modified your code as follows to get it to run: >>> >>> import Tkinter as tk >>> master = tk.Tk() >>> settings = tk.LabelFrame(master, text="Settings") >>> settings.grid(row=0, column=0) >>> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, >>> sticky=tk.E) >>> angles = tk.StringVar(value='radians') >>> tk.Radiobutton(settings, text="Degrees", variable=angles, >>> value='degrees').grid(row=0, column=1) >>> tk.Radiobutton(settings, text="Radians", variable=angles, >>> value='radians').grid(row=0, column=2) >>> master.mainloop() >>> >>> ...and on my Macosx running python 2.5.2 it runs fine, with buttons >>> selected. >>> >>> My bet is that angles is not in fact set, or is not set >>> to one of 'degrees' or 'radians'. Put a print statement to >>> see what value __main__.angles has at the point of >>> setting the variable angles. >>> >>> Mick >>> >>> >>> >>> On Fri, Aug 15, 2008 at 6:19 AM, Iain Day >>> wrote: >>>> Hi, >>>> >>>> I'm trying to create a preferences dialog. At the moment, I'm just >>>> reading a >>>> config file using ConfigParser and displaying this in a tkSimpleDialog. >>>> >>>> I've got some Entry widgets working okay, but I can't get the >>>> radiobuttons >>>> to work. The code is: >>>> >>>> import Tkinter as tk >>>> >>>> settings = tk.LabelFrame(master, text="Settings") >>>> settings.grid(row=0, column=0) >>>> >>>> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, >>>> sticky=tk.E) >>>> >>>> angles = tk.StringVar(value=__main__.angles) >>>> >>>> tk.Radiobutton(settings, text="Degrees", variable=angles, >>>> value='degrees').grid(row=0, column=1) >>>> >>>> tk.Radiobutton(settings, text="Radians", variable=angles, >>>> value='radians').grid(row=0, column=2) >>>> >>>> When I run this, angles is set to degrees but I don't get the radiobutton >>>> active (either of them). >>>> >>>> What am I doing wrong? >>>> >>>> Thanks, >>>> >>>> Iain >>>> >>>> _______________________________________________ >>>> Tkinter-discuss mailing list >>>> Tkinter-discuss at python.org >>>> http://mail.python.org/mailman/listinfo/tkinter-discuss >>>> >> _______________________________________________ >> Tkinter-discuss mailing list >> Tkinter-discuss at python.org >> http://mail.python.org/mailman/listinfo/tkinter-discuss >> From iain at day-online.org.uk.invalid Sun Aug 17 14:03:44 2008 From: iain at day-online.org.uk.invalid (Iain Day) Date: Sun, 17 Aug 2008 13:03:44 +0100 Subject: [Tkinter-discuss] initial state of radiobutton In-Reply-To: <47e491110808162105q67e6ef90wf17148678c33111e@mail.gmail.com> References: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> <47e491110808162105q67e6ef90wf17148678c33111e@mail.gmail.com> Message-ID: Sorry, forgot to say, on Mac OS 10.4.11, using Python 2.5.2 Iain Michael O'Donnell wrote: > Hi Iain, > > My earlier reply established that the radio widget IS functioning correctly > on your machine in the usual case. If there is still something wrong, I'd have > to see runnable code from your app which fails to set the radio. Can you > make a minimal case which uses the class structure you discuss, and > still doesn't work, and send it (probably as a compressed archive, > e.g., zip file). > > I'll then see if I can find the bug. What OS are you on? > > Mick > > On Sat, Aug 16, 2008 at 9:34 PM, Iain Day > wrote: >> Hi Mick, >> >> Sorry about that. The code below does work, however, in my case its a little >> more complex. I'll try and explain. I've put most of the code into different >> modules which get imported in the usual way, so I have one that has all the >> classes for the menu bar. There is also a class in here which generates the >> tkSimpleDialog for the preferences. Is is here that I've got the bit of code >> I posted below. >> >> __main__.angles is set correctly, and if I do: >> >> print tk.StringVar.get(angles) >> >> I get the correct result. >> >> I'm a little confused. Also if I put angles into an Entry widget it is >> correct. >> >> Thanks for your help, >> >> Iain >> >> Michael O'Donnell wrote: >>> Dear Iain, >>> >>> Makes it easier to test your code if you provide >>> a standalone example. >>> >>> I modified your code as follows to get it to run: >>> >>> import Tkinter as tk >>> master = tk.Tk() >>> settings = tk.LabelFrame(master, text="Settings") >>> settings.grid(row=0, column=0) >>> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, >>> sticky=tk.E) >>> angles = tk.StringVar(value='radians') >>> tk.Radiobutton(settings, text="Degrees", variable=angles, >>> value='degrees').grid(row=0, column=1) >>> tk.Radiobutton(settings, text="Radians", variable=angles, >>> value='radians').grid(row=0, column=2) >>> master.mainloop() >>> >>> ...and on my Macosx running python 2.5.2 it runs fine, with buttons >>> selected. >>> >>> My bet is that angles is not in fact set, or is not set >>> to one of 'degrees' or 'radians'. Put a print statement to >>> see what value __main__.angles has at the point of >>> setting the variable angles. >>> >>> Mick >>> >>> >>> >>> On Fri, Aug 15, 2008 at 6:19 AM, Iain Day >>> wrote: >>>> Hi, >>>> >>>> I'm trying to create a preferences dialog. At the moment, I'm just >>>> reading a >>>> config file using ConfigParser and displaying this in a tkSimpleDialog. >>>> >>>> I've got some Entry widgets working okay, but I can't get the >>>> radiobuttons >>>> to work. The code is: >>>> >>>> import Tkinter as tk >>>> >>>> settings = tk.LabelFrame(master, text="Settings") >>>> settings.grid(row=0, column=0) >>>> >>>> tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, >>>> sticky=tk.E) >>>> >>>> angles = tk.StringVar(value=__main__.angles) >>>> >>>> tk.Radiobutton(settings, text="Degrees", variable=angles, >>>> value='degrees').grid(row=0, column=1) >>>> >>>> tk.Radiobutton(settings, text="Radians", variable=angles, >>>> value='radians').grid(row=0, column=2) >>>> >>>> When I run this, angles is set to degrees but I don't get the radiobutton >>>> active (either of them). >>>> >>>> What am I doing wrong? >>>> >>>> Thanks, >>>> >>>> Iain >>>> >>>> _______________________________________________ >>>> Tkinter-discuss mailing list >>>> Tkinter-discuss at python.org >>>> http://mail.python.org/mailman/listinfo/tkinter-discuss >>>> >> _______________________________________________ >> Tkinter-discuss mailing list >> Tkinter-discuss at python.org >> http://mail.python.org/mailman/listinfo/tkinter-discuss >> From fredrik at pythonware.com Sun Aug 17 15:08:43 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Aug 2008 15:08:43 +0200 Subject: [Tkinter-discuss] initial state of radiobutton In-Reply-To: References: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> <47e491110808162105q67e6ef90wf17148678c33111e@mail.gmail.com> Message-ID: Iain Day wrote: > def edit_preferences(event=None): > prefs = Preferences(master, title="Preferences") > > class Preferences(tkSimpleDialog.Dialog): > def body(self, master): > settings = tk.LabelFrame(master, text="Settings") > settings.grid(row=0, column=0) > tk.Label(settings, text="Angular Units: ").grid(row=0, column=0, > sticky=tk.E) > angles = tk.StringVar(value='radians') self.angles = angles # keep a reference to the variable > tk.Radiobutton(settings, text="Degrees", > variable=angles,value='degrees').grid(row=0, column=1) > tk.Radiobutton(settings, text="Radians", > variable=angles,value='radians').grid(row=0, column=2) Widgets don't keep references to their option values, so unless you explicitly keep a reference to the variable yourself (e.g. via an instance attribute, as above), it'll be removed at the end of the method. From iain at day-online.org.uk.invalid Sun Aug 17 15:50:34 2008 From: iain at day-online.org.uk.invalid (Iain Day) Date: Sun, 17 Aug 2008 14:50:34 +0100 Subject: [Tkinter-discuss] initial state of radiobutton In-Reply-To: References: <47e491110808141638l4f60b72cw7eda862594c16bbd@mail.gmail.com> <47e491110808162105q67e6ef90wf17148678c33111e@mail.gmail.com> Message-ID: Fredrik Lundh wrote: > Iain Day wrote: > >> def edit_preferences(event=None): >> prefs = Preferences(master, title="Preferences") >> >> class Preferences(tkSimpleDialog.Dialog): >> def body(self, master): >> settings = tk.LabelFrame(master, text="Settings") >> settings.grid(row=0, column=0) >> tk.Label(settings, text="Angular Units: ").grid(row=0, >> column=0, sticky=tk.E) >> angles = tk.StringVar(value='radians') > > self.angles = angles # keep a reference to the variable > >> tk.Radiobutton(settings, text="Degrees", >> variable=angles,value='degrees').grid(row=0, column=1) >> tk.Radiobutton(settings, text="Radians", >> variable=angles,value='radians').grid(row=0, column=2) > > Widgets don't keep references to their option values, so unless you > explicitly keep a reference to the variable yourself (e.g. via an > instance attribute, as above), it'll be removed at the end of the method. Okay, thanks. Not quite sure I follow though, later in my code I have tk.Label(files, text="Working dir: ").grid(row=0, column=0, sticky=tk.E) tk.Entry(files, textvariable=workdir).grid(row=0, column=1, sticky=tk.W) and this worked okay, without the self.var = var bit. Is there a difference between the two? Thanks, Iain From alexnbryan at gmail.com Sun Aug 17 20:19:32 2008 From: alexnbryan at gmail.com (Alexnb) Date: Sun, 17 Aug 2008 11:19:32 -0700 (PDT) Subject: [Tkinter-discuss] putting a series of hyperlinks in a text widget In-Reply-To: References: <18948087.post@talk.nabble.com> <47e491110808162146x50f4b167h95c7dcd0c041664f@mail.gmail.com> <19017586.post@talk.nabble.com> Message-ID: <19022072.post@talk.nabble.com> Ya, I saw that but didn't help :( But its good, I got what I need. Fredrik Lundh wrote: > > Alexnb wrote: > >> You know, I think this is exactly what I was looking for. >> >> Thanks for your help! > > Here's the first hit for "tkinter hyperlink", btw: > > http://effbot.org/zone/tkinter-text-hyperlink.htm > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- View this message in context: http://www.nabble.com/putting-a-series-of-hyperlinks-in-a-text-widget-tp18948087p19022072.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From fredrik at pythonware.com Sun Aug 17 20:32:18 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 17 Aug 2008 20:32:18 +0200 Subject: [Tkinter-discuss] putting a series of hyperlinks in a text widget In-Reply-To: <19022072.post@talk.nabble.com> References: <18948087.post@talk.nabble.com> <47e491110808162146x50f4b167h95c7dcd0c041664f@mail.gmail.com> <19017586.post@talk.nabble.com> <19022072.post@talk.nabble.com> Message-ID: Alexnb wrote: > Ya, I saw that but didn't help :( It does *exactly* what you asked for, though. From dave.opstad at monotypeimaging.com Mon Aug 18 17:12:36 2008 From: dave.opstad at monotypeimaging.com (Dave Opstad) Date: Mon, 18 Aug 2008 08:12:36 -0700 Subject: [Tkinter-discuss] Unicode on Mac (yet again) In-Reply-To: Message-ID: Fred Mailhot wrote: > Greetings, > > I've followed some of the discussion on the list concerning the > problem of getting some Unicode characters to display properly. As > suggested in a few messages, I've recompiled my python to link to > Tcl/Tk8.5. I know this has succeeded, as running Tkinter._test() pops > up a dialog confirming that I'm using 8.5. > > Unfortunately, there still seem to be problems displaying Unicode > characters properly. The following snippet demonstrates (disclaimer: > I'm not a Tkinter guru by any means)... > > import Tkinter > root = Tkinter.Tk() > w1 = Tkinter.Button(root, text=u"\u026E", font=("Lucida Grande",24)) > w2 = Tkinter.Label(root, text=u"\u026E", font=("Lucida Grande",24)) > w1.pack() > w2.pack > > The Button displays the correct character (a digraph from the > International Phonetic Alphabet), whereas the Label displays what > looks like a Chinese kanji character...the same problem as in 8.4. > > Is there something I'm doing wrong? The first thing that strikes me is an endian issue. You're asking for Unicode 026E, but Unicode 6E02 might be what you're getting (and it's in the CJK ideograph range). Is there an endian compiler flag you need to set when you recompile your python for linking to Tcl/Tk 8.5? Dave From lee at sequans.com Tue Aug 19 00:30:47 2008 From: lee at sequans.com (Lee Walczak) Date: Mon, 18 Aug 2008 23:30:47 +0100 Subject: [Tkinter-discuss] configuring temporary entry widget of TableList Cell using Python Message-ID: <000b01c90182$10752a20$315f7e60$@com> Hi, I recently posted this to comp.lang.python & tcl, but have not had much luck with responses on how to do this. Really hoping you guys can help with me with this. No doubt the answer is right under my nose! Let me know if it is useful for me to provide a direct example of what I am trying to achieve. I really look forward to receiving correspondence on this! Best Regards, Lee Hi, I am using Tkinter & the Kevin Walzer's TableList Wrapper for python implemented GUI: http://tkinter.unpythonic.net/wiki/TableListWrapper The TableList has been extremely useful in allowing me to create my GUI for my engineering requirements, but I have hit a brick wall and need some assistance. "I am unable to configure the Temporary Embedded ComboBox List when the specific TableList cell is selected for editing" I have a registered the Bwidget Combobox widget so I can use this as an alternative temporary Entry Widget ( depending on the specific cell usage) thanks to some assistance from Kevin Walzer ( Many thanks ). I configure the particular cell's edit window (-editwindow ) for ComboBox which is working successfully. The problem I have is I wish to change the "-values" of the Temporary Combobox Widget i.e. a List that I can specify. When my "-editstartcommand" call is called I firstly request the pathname of the Temporary Embedded Widget using, TEW = editwinpath() I am then assuming (although I must be wrong!) that I can then do: TEW.configure( values=("my","list","of","Strings")) However, this leads to the exception error -> TEW does not contain such an attribute "configure". My reference for this procedure is (http://objectmix.com/tcl/377931- communicating-tablelist-embedded-widgets.html but also available from tcl.tk tablelist coding examples) : proc editStartCmd {tbl row col text} { set w [$tbl editwinpath] switch [$tbl columncget $col -name] { currency { # # Populate the ComboBox and make it non-editable # $w configure -values {Dollar Euro Yen ...} -editable no } . . . } return $text } It is this procedure I am trying to replicate in Python. Is it possible to guide help tell me the right approach here. Of course I can submit my code to help ( if this is useful ) but the problem I think clear to see from these summary details. Please take it easy on me, I am a HW engineer by trade and am slowly (but surely) gaining more knowledge & experience in the world of Python (and of course Tkinter)! B.Regards, Lee Walczak -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexnbryan at gmail.com Tue Aug 19 05:38:55 2008 From: alexnbryan at gmail.com (Alexnb) Date: Mon, 18 Aug 2008 20:38:55 -0700 (PDT) Subject: [Tkinter-discuss] getting width of a Frame Message-ID: <19043845.post@talk.nabble.com> I have two listBoxes in one Frame. I want to make them the same size. I want to make them half of the width of the Frame they are in. I just can't figure out how to get the width of a Frame, just a window. Help? -- View this message in context: http://www.nabble.com/getting-width-of-a-Frame-tp19043845p19043845.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From alexnbryan at gmail.com Tue Aug 19 07:30:56 2008 From: alexnbryan at gmail.com (Alexnb) Date: Mon, 18 Aug 2008 22:30:56 -0700 (PDT) Subject: [Tkinter-discuss] Problems with a scrollbar on a listbox Message-ID: <19044535.post@talk.nabble.com> So I have a listBox and a scrollbar, both in the same frame. I have them set up just as I do my text widgets, and they work just as they should. Here is how I have it: self.urlscrollbar = Scrollbar(self.insidebuffer1) self.urlscrollbar.pack(side=RIGHT, fill=Y) self.diclistBox = Listbox(self.insidebuffer1, selectmode=MULTIPLE, yscrollcommand=self.urlscrollbar.set) self.diclistBox.pack(side=TOP, anchor=N, fill=BOTH) I am on a mac if it matters. But what happens is they show up, and when the list in the listbox is big enough, the bar turns blue like it is able to scroll; but it doesn't function. Any ideas? Did I leave something out? -- View this message in context: http://www.nabble.com/Problems-with-a-scrollbar-on-a-listbox-tp19044535p19044535.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From michael.odonnell at uam.es Tue Aug 19 07:53:31 2008 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 19 Aug 2008 07:53:31 +0200 Subject: [Tkinter-discuss] getting width of a Frame In-Reply-To: <19043845.post@talk.nabble.com> References: <19043845.post@talk.nabble.com> Message-ID: <47e491110808182253x3ba6d095p2b66102829840793@mail.gmail.com> Hi Alex, Several issues here. 1) In some cases, the size a frame will eventually have depends on what is packed/gridded inside it. So it m,ay not be possible to tell the size of the frame before adding the list boxes. The exception here is if you use tell the frame to take the maximum space (e.g., for pack: expand=True, fill=BOTH for grid: sticky=NSEW You can then pack/grid your Frame, and then ask how big it is using frm.winfo_geometry() or frm.winfo_height() and frm.winfo_width() 2) You cannot get the frame's size until it is packed and displayed. So, what you can do is something like the following, using update: from Tkinter import * tk = Tk() Label(tk, text="HELLO").pack(side=TOP) fr=Frame(tk) fr.pack(side=TOP, fill=BOTH, expand=True) print "frame size before update: ", fr.winfo_width(), fr.winfo_height() fr.update() print "frame size after update: ", fr.winfo_width(), fr.winfo_height() tk.mainloop() Not always possible to do this, Mick On Tue, Aug 19, 2008 at 5:38 AM, Alexnb wrote: > > I have two listBoxes in one Frame. I want to make them the same size. I want > to make them half of the width of the Frame they are in. I just can't figure > out how to get the width of a Frame, just a window. Help? > -- > View this message in context: http://www.nabble.com/getting-width-of-a-Frame-tp19043845p19043845.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From michael.odonnell at uam.es Tue Aug 19 07:59:22 2008 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 19 Aug 2008 07:59:22 +0200 Subject: [Tkinter-discuss] Problems with a scrollbar on a listbox In-Reply-To: <19044535.post@talk.nabble.com> References: <19044535.post@talk.nabble.com> Message-ID: <47e491110808182259j6cc6c048hd9eb8ad6e928ec26@mail.gmail.com> Alex, To link a scroller to a widget, you need to link in both directions: not only setting the yscrollcommand of the ListBox but also: self.urlscrollbar.config(command=self. diclistBox.yview) Example 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, **keywords) 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) # insert the items for item in items: self.table.insert(END, item) On Tue, Aug 19, 2008 at 7:30 AM, Alexnb wrote: > > So I have a listBox and a scrollbar, both in the same frame. I have them set > up just as I do my text widgets, and they work just as they should. Here is > how I have it: > > self.urlscrollbar = Scrollbar(self.insidebuffer1) > self.urlscrollbar.pack(side=RIGHT, fill=Y) > > self.diclistBox = Listbox(self.insidebuffer1, selectmode=MULTIPLE, > yscrollcommand=self.urlscrollbar.set) > self.diclistBox.pack(side=TOP, anchor=N, fill=BOTH) > > I am on a mac if it matters. But what happens is they show up, and when the > list in the listbox is big enough, the bar turns blue like it is able to > scroll; but it doesn't function. Any ideas? Did I leave something out? > -- > View this message in context: http://www.nabble.com/Problems-with-a-scrollbar-on-a-listbox-tp19044535p19044535.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From alexnbryan at gmail.com Tue Aug 19 08:10:05 2008 From: alexnbryan at gmail.com (Alexnb) Date: Mon, 18 Aug 2008 23:10:05 -0700 (PDT) Subject: [Tkinter-discuss] Problems with a scrollbar on a listbox In-Reply-To: <47e491110808182259j6cc6c048hd9eb8ad6e928ec26@mail.gmail.com> References: <19044535.post@talk.nabble.com> <47e491110808182259j6cc6c048hd9eb8ad6e928ec26@mail.gmail.com> Message-ID: <19044814.post@talk.nabble.com> Excelent! That was exactly it. I just forgot to add that part in. Thanks!! Mick O'Donnell wrote: > > Alex, > > To link a scroller to a widget, you need to link in both directions: > not only setting the yscrollcommand of the ListBox but also: > > self.urlscrollbar.config(command=self. diclistBox.yview) > > Example 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, **keywords) > 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) > > # insert the items > for item in items: > self.table.insert(END, item) > > > > > On Tue, Aug 19, 2008 at 7:30 AM, Alexnb wrote: >> >> So I have a listBox and a scrollbar, both in the same frame. I have them >> set >> up just as I do my text widgets, and they work just as they should. Here >> is >> how I have it: >> >> self.urlscrollbar = Scrollbar(self.insidebuffer1) >> self.urlscrollbar.pack(side=RIGHT, fill=Y) >> >> self.diclistBox = Listbox(self.insidebuffer1, selectmode=MULTIPLE, >> yscrollcommand=self.urlscrollbar.set) >> self.diclistBox.pack(side=TOP, anchor=N, fill=BOTH) >> >> I am on a mac if it matters. But what happens is they show up, and when >> the >> list in the listbox is big enough, the bar turns blue like it is able to >> scroll; but it doesn't function. Any ideas? Did I leave something out? >> -- >> View this message in context: >> http://www.nabble.com/Problems-with-a-scrollbar-on-a-listbox-tp19044535p19044535.html >> Sent from the Python - tkinter-discuss mailing list archive at >> Nabble.com. >> >> _______________________________________________ >> Tkinter-discuss mailing list >> Tkinter-discuss at python.org >> http://mail.python.org/mailman/listinfo/tkinter-discuss >> > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- View this message in context: http://www.nabble.com/Problems-with-a-scrollbar-on-a-listbox-tp19044535p19044814.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From ggpolo at gmail.com Tue Aug 19 13:22:08 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Tue, 19 Aug 2008 08:22:08 -0300 Subject: [Tkinter-discuss] getting width of a Frame In-Reply-To: <19043845.post@talk.nabble.com> References: <19043845.post@talk.nabble.com> Message-ID: On Tue, Aug 19, 2008 at 12:38 AM, Alexnb wrote: > > I have two listBoxes in one Frame. I want to make them the same size. I want > to make them half of the width of the Frame they are in. I just can't figure > out how to get the width of a Frame, just a window. Help? Put them in a PanedWindow. > -- > View this message in context: http://www.nabble.com/getting-width-of-a-Frame-tp19043845p19043845.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- -- Guilherme H. Polo Goncalves From alexnbryan at gmail.com Wed Aug 20 00:01:30 2008 From: alexnbryan at gmail.com (Alexnb) Date: Tue, 19 Aug 2008 15:01:30 -0700 (PDT) Subject: [Tkinter-discuss] Scrollbar maybe not setting right on a text widget Message-ID: <19059580.post@talk.nabble.com> The reason I say "maybe" is because I am not sure if that is what is happening. What happens is that the textbox will fill up (with info the program puts in, not the user) and the text widget will be at the top, like you will be looking at the begining of the textbox, but the scrollbar starts at the bottom of the track. It thinks it is at the bottom, but if you press the down arrow, it resets and figures it out. I am wondering if I forgot code or put it out of order? Oh, and I am using a mac with leopard. Here is code: self.scrollbar = Scrollbar(self.textFrameBuffer) self.scrollbar.pack(side=RIGHT, fill=Y) self.text = Text(self.textFrameBuffer, yscrollcommand=self.scrollbar.set) self.text.pack(side=LEFT, fill=BOTH, expand=YES) self.scrollbar.config(command=self.text.yview) --------The Text is filled in after this point. However, I have done the exact same setup with a listbox, and it works just as it should----------- -- View this message in context: http://www.nabble.com/Scrollbar-maybe-not-setting-right-on-a-text-widget-tp19059580p19059580.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From lee at sequans.com Wed Aug 20 21:30:19 2008 From: lee at sequans.com (Lee Walczak) Date: Wed, 20 Aug 2008 20:30:19 +0100 Subject: [Tkinter-discuss] Tkinter and TableList - Configure the Temporary Embedded Widgets Message-ID: <000001c902fb$2ee24f40$8ca6edc0$@com> I actually post a topic relating to my problem on this mailing list a couple of days ago but I thought it could be useful to place an example of my problem here aswell. This a small piece of testcode that creates a TableList. When the cell is selected, a ComboBox Widget is used temporarily during the editing phase. It is during this ( EditStartCmd call) that I wish to configure the "values" of the Widget. My question is, ""How do I do this ?"" The code below returns the error when the cell is selected. : Traceback (most recent call last): File "D:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ return self.func(*args) File "D:\PythonWS\TEW Test.py", line 34, in EditStartCmd TEW.configure(values=("This","Is","A","Test")) # Here I "try" to configure the Temporary Widget AttributeError: '_tkinter.Tcl_Obj' object has no attribute 'configure' I has also provided a normal bwidget combox box ( which I use for the Temporary Embedded Widget). It shows the normal method of configuring the "values" is working, just the method I assume for embedded ones it not. Anyone who has experience in Tkinter & Tablelist would really help me here. It could be something really silly that I do not appreciate and any clues would really help! ---------------------------------- import Tkinter import bwidget import tktablelist root = Tkinter.Tk() TestFr = Tkinter.Frame(root) TestBox = bwidget.ComboBox(root) TestBox.configure( values = ("1","two","4rer")) class TableBuilder: def __init__(self, Frame, Titles): self.Table=tktablelist.TableList(Frame, editstartcommand=self.EditStartCmd, selecttype="cell", stretch = "all", width=20, ) root.tk.call('tablelist::addBWidgetComboBox') self.Table.pack() self.BuildTable(Titles) def BuildTable(self,Titles): I = 0 for Title in Titles: self.Table.insertcolumns("end", 0, Title) self.Table.columnconfigure("end",editable='yes', editwindow="ComboBox") I +=1 for row in range(10): self.Table.insert("end","") self.Table.rowconfigure("end", text=(row,row+1,row*row)) def EditStartCmd(self, table, row, col, text): TEW = self.Table.editwinpath() # Here I return the Temporary Widget pathname TEW.configure(values=("This","Is","A","Test")) # Configure the Temp Widget - This is wrong! what is right? Test = TableBuilder(TestFr,['A','B','C']) TestBox = bwidget.ComboBox(root) TestBox.configure( text=" This Works!", values = ("1","two","4rer")) TestFr.pack() TestBox.pack() Tkinter.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptg at clix.pt Fri Aug 22 19:17:56 2008 From: ptg at clix.pt (ptg at clix.pt) Date: Fri, 22 Aug 2008 18:17:56 +0100 Subject: [Tkinter-discuss] Tkinter, toplevel and images Message-ID: <34936.1219425476@clix.pt> An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Sat Aug 23 11:30:27 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 23 Aug 2008 11:30:27 +0200 Subject: [Tkinter-discuss] Tkinter, toplevel and images In-Reply-To: <34936.1219425476@clix.pt> References: <34936.1219425476@clix.pt> Message-ID: ptg at clix.pt wrote: > and I just can see a grey window with a "close" button... However, > when I try the same code with the root I can see both images... Can > anyone give me a tip? you need to make sure that you keep references to all photoimages that are being displayed; see http://effbot.org/tkinterbook/photoimage.htm#note From oclbdk at gmail.com Sun Aug 31 06:11:12 2008 From: oclbdk at gmail.com (Johnston Jiaa) Date: Sun, 31 Aug 2008 00:11:12 -0400 Subject: [Tkinter-discuss] Kinetic Scrolling and Keyboard Shortcuts in Menus Message-ID: I'm having trouble trying to make a kinetic scrolling canvas. The code looks something like this... def scroll(acceleration, speed): while speed >= 0: canvas.xview_scroll(-speed, "units") speed -= acceleration This doesn't update the drawing of the canvas in real-time (as in, every time xview_scroll is called)... it only updates the drawing after the while loop has already run, so you don't get to see it scroll, which is stupid. How can I get this to work properly? Also, I have set keyboard shortcuts for some functions in my program. The functions these shortcuts call are also linked to menu items in the menu bar. How can I get the menu labels to reflect the keyboard shortcuts for each relative command? I know I can set the shortcut as a string in the label manually, but it will be stupid, not flush with the right edge of the menu, like in other programs. Thanks for helping my program not be stupid From ggpolo at gmail.com Sun Aug 31 19:03:14 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Sun, 31 Aug 2008 14:03:14 -0300 Subject: [Tkinter-discuss] Kinetic Scrolling and Keyboard Shortcuts in Menus In-Reply-To: References: Message-ID: On Sun, Aug 31, 2008 at 1:11 AM, Johnston Jiaa wrote: > I'm having trouble trying to make a kinetic scrolling canvas. The code > looks something like this... > > def scroll(acceleration, speed): > while speed >= 0: > canvas.xview_scroll(-speed, "units") > speed -= acceleration > > This doesn't update the drawing of the canvas in real-time (as in, every > time xview_scroll is called)... it only updates the drawing after the while > loop has already run, so you don't get to see it scroll, which is stupid. > How can I get this to work properly? You will need a canvas.update() after that .xview_scroll But, why aren't you using "after" instead of a while loop for this ? > > > Also, I have set keyboard shortcuts for some functions in my program. The > functions these shortcuts call are also linked to menu items in the menu > bar. How can I get the menu labels to reflect the keyboard shortcuts for > each relative command? I know I can set the shortcut as a string in the > label manually, but it will be stupid, not flush with the right edge of the > menu, like in other programs. > There are actually two question here. For the later the answer is.. instead of setting the shortcut it in the label, use the accelerator option to set it. The former is about reflecting keyboard shortcuts in menu labels, for this you will need to roll your own solution or try finding someone that already did it. > > Thanks for helping my program not be stupid > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- -- Guilherme H. Polo Goncalves From msa01 at bitflipper.ca Sun Aug 31 20:47:20 2008 From: msa01 at bitflipper.ca (Cam Farnell) Date: Sun, 31 Aug 2008 15:47:20 -0300 Subject: [Tkinter-discuss] Kinetic Scrolling and Keyboard Shortcuts in Menus In-Reply-To: References: Message-ID: <48BAE738.10106@bitflipper.ca> I ran into exactly this keyboard shortcut issue while writing the Rapyd-Tk Python development environment (http://www.bitflipper.ca/rapyd/). My solution is based on these functions, where the left part is the usual menu label and the right part is the shortcut. If the length of the shortcut text varies a lot you can compute the width on the fly as is done in Rapyd, otherwise just use some reasonable constant. def PadToWidth(LeftPart,RightPart,Width,Widget): """ Given left and right parts, return string of specified width in pixels. o "LeftPart" is the string to be left justified in the result. o "RightPart" is the string to be right justified in the result. o "Width" is the desired width, in pixels, of the result. o "Widget" the calculation is done with reference to the font set for this widget. Note that since we pad with space characters, the result will be as close as possible to the target size but will not necessarily be exactly the number of pixels requested. """ UsedPixels = TextMeasure(LeftPart+RightPart,Widget) PadPixels = Width - UsedPixels PadCount = int(round(float(PadPixels) / float(TextMeasure(' ',Widget)))) return '%s%s%s'%(LeftPart,' '*PadCount,RightPart) def TextMeasure(Text,Widget): """=u Measure size of "Text", in pixels, if displayed in "Widget". """ return int(Widget.tk.call("font", "measure", Widget["font"] ,"-displayof", Widget.master, Text )) Johnston Jiaa wrote: > > Also, I have set keyboard shortcuts for some functions in my program. > The functions these shortcuts call are also linked to menu items in the > menu bar. How can I get the menu labels to reflect the keyboard > shortcuts for each relative command? I know I can set the shortcut as a > string in the label manually, but it will be stupid, not flush with the > right edge of the menu, like in other programs. > > > Thanks for helping my program not be stupid From ggpolo at gmail.com Sun Aug 31 21:19:19 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Sun, 31 Aug 2008 16:19:19 -0300 Subject: [Tkinter-discuss] Kinetic Scrolling and Keyboard Shortcuts in Menus In-Reply-To: <48BAE738.10106@bitflipper.ca> References: <48BAE738.10106@bitflipper.ca> Message-ID: On Sun, Aug 31, 2008 at 3:47 PM, Cam Farnell wrote: > I ran into exactly this keyboard shortcut issue while writing the Rapyd-Tk > Python development environment (http://www.bitflipper.ca/rapyd/). My > solution is based on these functions, where the left part is the usual menu > label and the right part is the shortcut. If the length of the shortcut text > varies a lot you can compute the width on the fly as is done in Rapyd, > otherwise just use some reasonable constant. > Why did you use that instead of using the accelerator option ? Ok, the accelerator text doesn't go all the way to the right in the menu but they get are all aligned and you don't have to worry about doing anything else, and it is not that bad after all (not as I see at least). I'm attaching an image so you can confirm that you dislike its behavior. > > def PadToWidth(LeftPart,RightPart,Width,Widget): > """ > Given left and right parts, return string of specified width in pixels. > o "LeftPart" is the string to be left justified in the result. > o "RightPart" is the string to be right justified in the result. > o "Width" is the desired width, in pixels, of the result. > o "Widget" the calculation is done with reference to the font set for this > widget. > Note that since we pad with space characters, the result will be as > close as > possible to the target size but will not necessarily be exactly the > number > of pixels requested. > """ > UsedPixels = TextMeasure(LeftPart+RightPart,Widget) > PadPixels = Width - UsedPixels > PadCount = int(round(float(PadPixels) / float(TextMeasure(' ',Widget)))) > return '%s%s%s'%(LeftPart,' '*PadCount,RightPart) > > def TextMeasure(Text,Widget): > """=u > Measure size of "Text", in pixels, if displayed in "Widget". > """ > return int(Widget.tk.call("font", "measure", Widget["font"] > ,"-displayof", Widget.master, Text )) > > > > Johnston Jiaa wrote: > >> >> Also, I have set keyboard shortcuts for some functions in my program. The >> functions these shortcuts call are also linked to menu items in the menu >> bar. How can I get the menu labels to reflect the keyboard shortcuts for >> each relative command? I know I can set the shortcut as a string in the >> label manually, but it will be stupid, not flush with the right edge of the >> menu, like in other programs. >> >> >> Thanks for helping my program not be stupid > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- -- Guilherme H. Polo Goncalves -------------- next part -------------- A non-text attachment was scrubbed... Name: menu_img.png Type: image/png Size: 5347 bytes Desc: not available URL: