Python getting variable from this function to use in another file?

Im trying to get a return value from a function I have. I am getting the value but it is running through the function again and then getting the value even though i just want the value.

import pygame

def create_input_window():
    pygame.init()
    screen_width = 400
    screen_height = 150
    screen = pygame.display.set_mode((screen_width, screen_height))
    pygame.display.set_caption("Input Window")
    
    input_font = pygame.font.Font(None, 32)
    input_text = ""
    city_input = ""
    input_active = True
    city_entered = False

    while input_active:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                return None, None

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    if not city_entered:
                        city_entered = True
                    else:
                        input_active = False
                elif event.key == pygame.K_BACKSPACE:
                    if not city_entered:
                        input_text = input_text[:-1]
                    else:
                        city_input = city_input[:-1]
                else:
                    if not city_entered:
                        input_text += event.unicode
                    else:
                        city_input += event.unicode

        screen.fill((255, 255, 255))  # Clear the screen
        pygame.draw.rect(screen, (0, 0, 0), (50, 10, 300, 50), 2)  # Draw input box for input_text
        pygame.draw.rect(screen, (0, 0, 0), (50, 70, 300, 50), 2)  # Draw input box for city_input

        text_surface = input_font.render(input_text, True, (0, 0, 0))
        screen.blit(text_surface, (55, 15))  # Display input_text

        text_surface = input_font.render(city_input, True, (0, 0, 0))
        screen.blit(text_surface, (55, 75))  # Display city_input

        pygame.display.update()

    with open("input.txt", "w") as file:
        file.write(input_text)

    return str(city_input)

def get_city_input():
    city_input = create_input_window()
    return city_input


def main():
    while True:
        city_input = get_city_input()
        print("City name:", city_input)
if __name__ == "__main__":
    main()

I tried using a global variable instead of the function to get the variable but i dont know if i did it correctly. I asked chatgpt and got this which is similar to what I tried. I also am not too familiar with python and how it works.
import pygame

Global variable to store the city input

city_input = “”

def create_input_window():
global city_input # Access the global city_input variable
pygame.init()
screen_width = 400
screen_height = 150
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption(“Input Window”)

input_font = pygame.font.Font(None, 32)
input_text = ""
input_active = True
city_entered = False

while input_active:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            return None

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RETURN:
                if not city_entered:
                    city_entered = True
                else:
                    input_active = False
            elif event.key == pygame.K_BACKSPACE:
                if not city_entered:
                    input_text = input_text[:-1]
                else:
                    city_input = city_input[:-1]
            else:
                if not city_entered:
                    input_text += event.unicode
                else:
                    city_input += event.unicode

    screen.fill((255, 255, 255))  # Clear the screen
    pygame.draw.rect(screen, (0, 0, 0), (50, 10, 300, 50), 2)  # Draw input box for input_text
    pygame.draw.rect(screen, (0, 0, 0), (50, 70, 300, 50), 2)  # Draw input box for city_input

    text_surface = input_font.render(input_text, True, (0, 0, 0))
    screen.blit(text_surface, (55, 15))  # Display input_text

    text_surface = input_font.render(city_input, True, (0, 0, 0))
    screen.blit(text_surface, (55, 75))  # Display city_input

    pygame.display.update()

with open("input.txt", "w") as file:
    file.write(input_text)

def get_city_input():
global city_input # Access the global city_input variable
return city_input

def main():
create_input_window() # Call create_input_window once to set up the input window
while True:
city_input = get_city_input()
print(“City name:”, city_input)

if name == “main“:
main()

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật