Can this be reversed (Tkinter)?

John J. Lee jjl at
Sat Jan 3 00:19:22 CET 2004

"mark" <mark at> writes:

> 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))?

def geometry_tuple_from_string(text):
    a, rest = text.split("x")
    b, c, d = rest.split("+")
    return tuple([int(x) for x in (a, b, c, d)])

print geometry_tuple_from_string("100x150+25+25")


More information about the Python-list mailing list