Re: re.sub do not replace portion of match
Thanks Duncan, I did look at that, but it was kinda greek to me. Thanks for pulling out the part I was looking for that should do the trick. Jonathan > http://www.python.org/doc/current/library/re.html#re.sub > > > Backreferences, such as \6, are replaced with the substring matched by > > group 6 in the pattern. -- http://mail.python.org/mailman/listinfo/python-list
re.sub do not replace portion of match
Hi, Is there a way to flag re.sub not to replace a portion of the string? I have a very long string that I want to add two new line's to rather than one, but keep the value X: string = "testX.\n.today" <-- note X is a value string = re.sub("testX.\n.","testX.\n\n.", string) This just replaces X with the replacement string. Thanks, Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Tkinter -- the best way to make a realtime loop
What's the best way to make a realtime loop in Tkinter? I know in perl you can use "repeat" and it will call a function every x seconds, in python it seems like "after" may be the equivalent though it doesn't seem to behave like the perl repeat function. Any ideas? Thanks, Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter -- the best way to make a realtime loop
Thank you both for your replies. I had something similar to this: def incr(): var.set(1 + var.get()) root.after(1000, incr) except I had an extra set of parenthesis... def incr(): var.set(1 + var.get()) root.after(1000, incr()) on the function which was screwing it up. Also needed to have a root.update() to refresh the GUI. Thanks again, Jon -- http://mail.python.org/mailman/listinfo/python-list
Re: sort values from dictionary of dictionaries python 2.4
On Nov 9, 2:27 pm, Peter Otten <__pete...@web.de> wrote: > J Wolfe wrote: > > I would like to sort this dictionary by the values of the inner > > dictionary ‘ob’ key. > > Python's built-in dictionary is unsorted by design. > > > > > mydict = > > {’WILW1′: {’fx’: ‘8.1′, ‘obtime’: ‘2009-11-07 06:45:00′, ‘ob’: ‘6.9′}, > > ‘GRRW1′: {’fx’: ‘12.8′, ‘obtime’: ‘2009-11-07 04:15:00′, ‘ob’: ‘6.7′}, > > ‘NASW1′: {’fx’: ‘6.8′, ‘obtime’: ‘2009-11-07 06:30:00′, ‘ob’: ‘7.1′} > > } > > > In this case, this would become: > > > mysorteddic = > > {’NASW1′: {’fx’: ‘6.8′, ‘obtime’: ‘2009-11-07 06:30:00′, ‘ob’: ‘7.1′}, > > ‘WILW1′: {’fx’: ‘8.1′, ‘obtime’: ‘2009-11-07 06:45:00′, ‘ob’: ‘6.9′}, > > ‘GRRW1′: {’fx’: ‘12.8′, ‘obtime’: ‘2009-11-07 04:15:00′, ‘ob’: ‘6.7′} > > } > > > I have had no luck in trying to figure this out. I am restricted to > > using python 2.4.3. > > > Any help would be appreciated! > > You may be able to work around that limitation by putting the dict items > into a list and sort that: > > >>> for item in sorted(mydict.items(), key=lambda (k, v): float(v["ob"]), > > reverse=True): > ... print item > ... > ('NASW1', {'fx': '6.8', 'obtime': '2009-11-07 06:30:00', 'ob': '7.1'}) > ('WILW1', {'fx': '8.1', 'obtime': '2009-11-07 06:45:00', 'ob': '6.9'}) > ('GRRW1', {'fx': '12.8', 'obtime': '2009-11-07 04:15:00', 'ob': '6.7'}) > > Peter Thanks Peter, That worked! :-) -- http://mail.python.org/mailman/listinfo/python-list
Print to Printer Tkinter Text
Hi, Is there a way to print the format of a Tkinter text box to a color printer with its tags, e.g. a blue text at font size 18 and bold will like it displays? Thanks, Jonathan -- http://mail.python.org/mailman/listinfo/python-list
frames in toplevel Tkinter
Probably a stupid question, but can you have a frames in a toplevel widget? Anything I try to put in a frame goes back to the main or root widget and not the toplevel or pop-up widget. Thanks for the help! Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: frames in toplevel Tkinter
On Dec 16, 11:09 pm, J Wolfe wrote: > Probably a stupid question, but can you have a frames in a toplevel > widget? Anything I try to put in a frame goes back to the main or root > widget and not the toplevel or pop-up widget. > > Thanks for the help! > Jonathan Thank you John, from Tkinter import * root = Tk() Label(root, text='This is the root window').pack() top = Toplevel(root) fr = Frame(top) # frame child of Toplevel called top fr.pack() Label(fr, text='This is in a frame in the Toplevel window').pack() root.mainloop() I swear I tried that about 20 times yesterday...and it kept putting it in my main window. Perhaps I had a naming issue. Thanks! Jonathan -- http://mail.python.org/mailman/listinfo/python-list
ScrolledText get xy index of rowheader component?
Hi, I tried to get the xycoordinate of a click of the rowheader column of Pmw's ScrolledText...and it returns the xycoordinate of the text portion...even though I supplied it with the rowheader component. self.scrolledtext.component('rowheader').index("@%d,%d" % (event.x,event.y)) What am I doing wrong? the call to my main scrolledtext looks something like this... self.scrolledtext.index("@%d,%d" % (event.x,event.y)) and works as intended. Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: ScrolledText get xy index of rowheader component?
Nevermind I figured it out... I set self.dummyvar = self.scrolledtext.component('rowheader') and then did something like so self.dummyvar.index("@%d,%d" % (event.x,event.y)) not sure why it worked like that...but it did :-) -- http://mail.python.org/mailman/listinfo/python-list
passing menu label to function
Hi, I would like to pass the label name of a menu to the command it is calling, is that possible? self.menuitem.menu.add_command(label="pass this",command = lambda i = self.self.menuitem.menu.cget("label"): self.function(i)) def function(self, i) print i # print the label name Any help would be appreciated! Thanks! Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: passing menu label to function
Thanks Peter, I figured out an alternative just as you posted your response, I just looped through the buttons I wanted to add and used the loop variable to label the item and then passed it to the function, though your way seems much more robust. Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list
Pmw optionmenu color
Hello, It seems like this should be easy to do... change the background color of the Pmw optionmenu. I have not been able to find this. Anyone have a hint or know how to do this? Thanks, Jonathan -- http://mail.python.org/mailman/listinfo/python-list
How do you implement a Progress Bar
I would really appreciate some help with this. I'm fairly new to using classes...What am I doing wrong? All I get is a blank window. I can't seem to figure out how to initialize this Progress Bar. Thanks, Jonathan ##file Meter.py from Tkinter import * class Meter(Frame): '''A simple progress bar widget.''' def __init__(self, master, fillcolor='orchid1', text='',value=0.0, **kw): Frame.__init__(self, master, bg='white', width=350,height=20) self.configure(**kw) self._c = Canvas(self, bg=self['bg'],width=self['width'], height=self['height'],highlightthickness=0, relief='flat',bd=0) self._c.pack(fill='x', expand=1) self._r = self._c.create_rectangle(0, 0, 0, int(self['height']), fill=fillcolor, width=0) self._t = self._c.create_text(int(self['width'])/2, int(self['height'])/2, text='') self.set(value, text) def set(self, value=0.0, text=None): #make the value failsafe: if value < 0.0: value = 0.0 elif value > 1.0: value = 1.0 if text == None: #if no text is specified get the default percentage string: text = str(int(round(100 * value))) + ' %' self._c.coords(self._r, 0, 0, int(self['width']) * value, int(self['height'])) self._c.itemconfigure(self._t, text=text) root=Tk() f=Meter(root) for i in range(100): f.set(i,"Hello") print i mainloop() -- http://mail.python.org/mailman/listinfo/python-list