Skip to content
The Chat Archive
chatgpt-4o-latest-20250326· OpenAI LMArena Human Preference 140K

i want a code in python which open browser through txt file first browser left top 2nd…

  1. User

    i want a code in python which open browser through txt file first browser left top 2nd browser right top 3rd browser bottom left and 4th browser bottom right and so on at a time four browser done and work on next browsers shows popup for confirmation to continue

  2. Assistant

    Here's a Python script that does what you've described:

    • Reads URLs from a .txt file.
    • Opens four browser windows at a time.
    • Positions them as:
      1. Top-left
      2. Top-right
      3. Bottom-left
      4. Bottom-right
    • After opening and positioning each group of 4, it shows a pop-up asking to continue.

    ✅ Requirements:

    Install pyautogui and pymsgbox for screen positioning and confirmation dialogs:

    pip install pyautogui pymsgbox
    

    This script assumes you are using Windows with a 1920x1080 screen resolution. You can adjust window positions for other resolutions easily in the code.


    📄 Sample urls.txt (one URL per line):

    https://example1.com
    https://example2.com
    https://example3.com
    https://example4.com
    https://example5.com
    https://example6.com
    

    🧠 Python Script:

    import webbrowser
    import time
    import pyautogui
    import pymsgbox
    
    # Customize based on your screen
    SCREEN_WIDTH, SCREEN_HEIGHT = pyautogui.size()
    
    # Browser window size and positions (for 1920x1080)
    WINDOW_WIDTH = int(SCREEN_WIDTH / 2)
    WINDOW_HEIGHT = int(SCREEN_HEIGHT / 2)
    
    positions = [
        (0, 0),  # Top-left
        (WINDOW_WIDTH, 0),  # Top-right
        (0, WINDOW_HEIGHT),  # Bottom-left
        (WINDOW_WIDTH, WINDOW_HEIGHT),  # Bottom-right
    ]
    
    def open_and_position_browser(url, position):
        webbrowser.open(url)
        time.sleep(2)  # Give browser time to open
        # Bring last opened window to front and move it
        pyautogui.hotkey('alt', 'space')  # Open window context menu
        time.sleep(0.3)
        pyautogui.press('m')  # Select Move
        time.sleep(0.3)
        pyautogui.moveTo(position[0] + 10, position[1] + 10)
        pyautogui.click()
        pyautogui.moveTo(position[0], position[1], duration=0.5)
        time.sleep(0.5)
    
    def main():
        # Read URLs
        with open('urls.txt', 'r') as f:
            urls = [line.strip() for line in f if line.strip()]
    
        index = 0
        while index < len(urls):
            group = urls[index:index+4]
            for i, url in enumerate(group):
                print(f"Opening {url} at position {positions[i]}")
                open_and_position_browser(url, positions[i])
                time.sleep(1)
            index += 4
            if index < len(urls):
                pymsgbox.alert("Press OK to open next set of browsers...", "Continue?")
                time.sleep(1)
    
    if __name__ == "__main__":
        main()
    

    🛠️ Notes:

    • Browser Control: This script uses webbrowser which opens the system's default browser. All tabs open in new windows.
    • Positioning: The script sends keyboard commands to "move" the last window.
    • Windows Only: For now, window movement logic (Alt + Space → M) works on Windows. You’d need different handling for macOS/Linux.
    • Full-screen apps may interfere with UI automation.

    Would you like a version that works with Chrome specifically or supports multiple monitors?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.