Can this be reversed (Tkinter)?

Fredrik Lundh fredrik at pythonware.com
Sat Jan 3 10:46:39 EST 2004


Dave Brueck wrote:

> > I am looking at the format used by root.geometry().  The string returned
> > from root.geometry() is "%dx%d+%d+%d".  Is there a quick and painless
> > way to extract the values from that string (i.e., "100x150+25+25" =>
> > (100,150,25,25))?
>
> How about:
>
> s = '100x150+25+25'
> import re
> reg = re.compile('(\d+)x(\d+)\+(\d+)\+(\d+)')
> [int(x) for x in reg.match(s).groups()]

note that the offsets may be negative; this pattern should work
a bit better:

    "(\d+)x(\d+)([-+]\d+)([-+]\d+)"

</F>







More information about the Python-list mailing list