util.urlDialog module¶
Asking for a URL (askURL()): the counterpart, for a file somewhere other than this computer (eg: on the web), of tkinter.filedialog.askopenfilename() – as “Open Location…” is to “Open…” in a web browser. (The file dialogs are the platform’s own – on macOS, its open panel – and can’t be extended to take a URL.)
Created on Oct 12, 2026
Code author: Rob Kremer <robkremer@me.com>
- util.urlDialog.SCHEMES = ('http', 'https', 'file')¶
The kinds of URL askURL() takes, unless told otherwise.
- util.urlDialog.urlProblem(url: str, schemes: tuple[str, ...] = ('http', 'https', 'file')) str | None¶
- Parameters:
url (str)
schemes (tuple[str, ...]) – The kinds of URL that will do.
- Returns:
What’s wrong with url as a URL (eg: no “https://”), or None if it looks right. (Whether there’s anything there isn’t checked.)
- Return type:
Optional[str]
- class util.urlDialog.URLDialog(parent: Misc, title: str, prompt: str = '', initial: str = '', recent: list[str] = [], check: Callable[[str], str | None] | None = None, schemes: tuple[str, ...] = ('http', 'https', 'file'))¶
Bases:
ToplevelA URL to type (or paste), checked before it’s taken (see askURL()). Modal: show() returns it, if OK’d.
- __init__(parent: Misc, title: str, prompt: str = '', initial: str = '', recent: list[str] = [], check: Callable[[str], str | None] | None = None, schemes: tuple[str, ...] = ('http', 'https', 'file'))¶
Construct a toplevel widget with the parent MASTER.
Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, menu, relief, screen, takefocus, use, visual, width.
- result: str | None¶
- ok() None¶
Take the URL – if it looks right (see urlProblem()), and check (if there is one) finds nothing wrong with it; else say what’s wrong.
- show() str | None¶
- Returns:
The URL, if OK’d; else None.
- util.urlDialog.askURL(parent: Misc, title: str = 'Open URL', prompt: str = '', initial: str = '', recent: list[str] = [], check: Callable[[str], str | None] | None = None, schemes: tuple[str, ...] = ('http', 'https', 'file')) str | None¶
Ask for a URL.
- Parameters:
parent (tk.Misc) – The window it’s over.
title (str)
prompt (str) – Said above where it’s typed.
initial (str) – What’s there to start with.
recent (list[str]) – URLs to choose from (eg: those used recently).
check (Optional[Callable[[str], Optional[str]]]) – Given the URL, what’s wrong with it (eg: there’s nothing there, or it isn’t the kind of file that’s wanted), or None if it’ll do: until it is, it’s asked for again. (Exceptions it raises are what’s wrong.)
schemes (tuple[str, ...]) – The kinds of URL that will do.
- Returns:
The URL, or None if cancelled.
- Return type:
Optional[str]