Tk_CreateWindow(3tk)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– Tk_CreateWindow β€” the Tk Library Procedures era πŸ’–

okay bestie, gather round, because we're about to talk about the manual page for Tk_CreateWindow(3tk) from the Tk Library Procedures and it is genuinely so much. creating and deleting windows, deferred creation, all of it. let's go 🫢


✨ NAME ✨

Tk_CreateWindow, Tk_CreateWindowFromPath, Tk_DestroyWindow, Tk_MakeWindowExist β€” create or delete window. yes queen, that's the whole job description πŸ’…


✨ SYNOPSIS ✨

#include <tk.h>

Tk_Window
Tk_CreateWindow(interp, parent, name, topLevScreen)

Tk_Window
Tk_CreateAnonymousWindow(interp, parent, topLevScreen)

Tk_Window
Tk_CreateWindowFromPath(interp, tkwin, pathName, topLevScreen)

Tk_DestroyWindow(tkwin)

Tk_MakeWindowExist(tkwin)

✨ ARGUMENTS ✨

  • Tcl_Interp *interp (out) β€” the Tcl interpreter we use for reporting errors. and like, if nothing goes wrong? *interp doesn't get touched at all. no notes, she's unbothered ✨
  • Tk_Window parent (in) β€” a token for the window that's gonna be the logical parent of the new baby window 🍼
  • const char *name (in) β€” the name for this window. it must be unique among all the children of the same parent, no sharing, we don't do that here πŸ™…
  • const char *topLevScreen (in) β€” same format as screenName. if it's NULL, the new window gets created as an internal window. if it's non-NULL, the new window is a top-level window on screen topLevScreen. and if topLevScreen is an empty string ("")? then the new window is created as a top-level window of the parent's screen πŸ–₯️
  • Tk_Window tkwin (in) β€” a token for a window.
  • const char *pathName (in) β€” the name of the new window, given as a path name within the application (like .a.b.c) πŸ›€οΈ

✨ DESCRIPTION ✨

So. Tk_CreateWindow, Tk_CreateAnonymousWindow, and Tk_CreateWindowFromPath are the procedures you use to make new windows for Tk-based applications. each one hands you back a token you can use to mess with that window in other Tk library calls. and if the window couldn't be created? you get NULL back and the result of interpreter interp gets modified to hold an error message. sad girl hours 😭

Tk does two kinds of windows, and you need to know both:

  • an internal window β€” an interior window of a Tk application. think scrollbar, menu bar, button. the little guys πŸŽ€
  • a top-level window β€” one created as a child of a screen's root window instead of as an interior window, but which is logically part of some existing main window. pop-up menus and dialog boxes live here. main character energy fr fr πŸ‘‘

New windows get created by calling Tk_CreateWindow. if topLevScreen is NULL, congrats, internal window. if topLevScreen is non-NULL, it's a top-level window β€” topLevScreen names the screen, and the new window gets created as a child of the root window of topLevScreen. either way, Tk treats the new window as the logical child of parent: the path name reflects that, options can be specified for it under that assumption, all of it. the only difference is that the new X window for a top-level window won't be a child of parent's X window. like, a pull-down menu's parent would be the button-like window used to invoke it, which is itself a child of the menu bar window. a dialog box might have the application's main window as its parent. the way that works is so iconic honestly πŸ’…

Tk_CreateAnonymousWindow differs from Tk_CreateWindow because it creates an unnamed window. this one is manipulatable only through C interfaces β€” Tcl scripts can't see it at all, she's private, she's mysterious πŸ•ΆοΈ. and yes, both interior windows and top-level windows can be made with Tk_CreateAnonymousWindow.

Tk_CreateWindowFromPath is the alternate route to specifying new windows. here you give a token for any window in the target application (tkwin) plus a path name for the new window. same effect as Tk_CreateWindow, and it can do both top-level and internal windows depending on topLevScreen. and just like with Tk_CreateWindow: the parent of the new window must exist at the time of the call, but the new window must not already exist. rules are rules 🚨

here's the tea: the window creation procedures do not actually issue the command to X to create a window. instead they make a local data structure tied to the window and defer creating the X window. the window actually gets created by the first call to Tk_MapWindow. deferred creation means you can modify all kinds of stuff about the window (its size, background color, etc.) after its creation without incurring any overhead in the X server. and when the window finally gets mapped, all the window attributes can be set while creating the window. efficient queen ⭐

and ngl, the value returned by a window-creation procedure is not the X token for the window. it literally cannot be, since X hasn't been asked to create the window yet. instead it's a token for Tk's local data structure for the window. most Tk library procedures take Tk_Window tokens rather than X identifiers. the actual X window identifier can be retrieved from the local data structure using the Tk_WindowId macro β€” check the manual entry for Tk_WindowId for the details πŸ”

Tk_DestroyWindow deletes a window and all the data structures associated with it, including any event handlers created with Tk_CreateEventHandler. plus, Tk_DestroyWindow deletes any children of tkwin recursively β€” and "children" here is the Tk sense of the word: all windows that were created with the given window as parent. gone, all of them πŸ’€

if tkwin is an internal window, event handlers interested in destroy events get invoked immediately. if tkwin is a top-level or main window, those event handlers get invoked later, after X has seen the request and returned an event for it. timing matters, bestie ⏳

and if a window has been created but hasn't been mapped, so no X window exists yet, you can force the X window into existence by calling Tk_MakeWindowExist. this procedure issues the X commands to instantiate the window given by tkwin. manifesting, but make it X πŸ¦‹


✨ KEYWORDS ✨

create, deferred creation, destroy, display, internal window, screen, top-level window, window 🌸


and that's the whole page bestie!! this one's from Tk, version 4.2, dated... well, it's the Tk_CreateWindow(3tk) page, 4.2 era, and honestly it ate. go make some windows, or delete them, either way slay πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from