Design a program in Python that converts a text string to a titlecase.
str = "Hello World"
def to_titlecase(str):
    new_str = ""
    for word in str.split(): 
        new_str += word.capitalize() + " "
    return new_str.strip()

print(to_titlecase("Hello World"))