Tk_GetPixelsFromObj(3tk)
π Tk_GetPixelsFromObj β bestie's guide to screen units π
okay so. this is Tk_GetPixelsFromObj(3tk), a page from the Tk Library Procedures collection, and it's literally the group chat where strings meet screen distances. you bring a number, you bring a unit, and Tk hands you back pixels or millimeters. no cap. π
β¨ NAME β¨
Tk_GetPixelsFromObj, Tk_GetPixels, Tk_GetMMFromObj, Tk_GetScreenMM, Tk_GetDoublePixelsFromObj β the whole squad that translates between strings and screen units π¦
πΈ SYNOPSIS πΈ
#include <tk.h>
int
Tk_GetPixelsFromObj(interp, tkwin, objPtr, intPtr)
int
Tk_GetDoublePixelsFromObj(interp, tkwin, objPtr, doublePtr)
int
Tk_GetPixels(interp, tkwin, string, intPtr)
int
Tk_GetMMFromObj(interp, tkwin, objPtr, doublePtr)
int
Tk_GetScreenMM(interp, tkwin, string, doublePtr)
π ARGUMENTS π
Tcl_Interp *interp(in) β the interpreter that handles error reporting. if something goes sideways, this is where the drama gets posted. πTk_Window tkwin(in) β the window whose screen geometry is what decides how absolute units turn into pixels. geometry queen behavior. πTcl_Obj *objPtr(in/out) β its string value says how far something is on screen; the internal rep gets modified so the converted distance is cached for later. glow-up of an object fr fr. β¨const char *string(in) β same energy asobjPtr, except the distance spec arrives as a plain string instead.int *intPtr(out) β pointer to where the converted distance in pixels goes to live. πdouble *doublePtr(out) β pointer to where the converted distance in millimeters gets stored.
π DESCRIPTION π
so these procedures take a spec of a distance on screen (objPtr or string) and compute the matching distance, either as integer pixels or as floating-point millimeters. either way, objPtr or string describes a screen distance as a floating-point number followed by one of these little unit characters. the unit character is doing the main character work here:
<none>β no character? the number is just a distance in pixels. simple. iconic.cβ the number is a distance in centimeters on the screen.iβ the number is a distance in inches on the screen.mβ the number is a distance in millimeters on the screen.pβ the number is a distance in printer's points (1/72 inch) on the screen.
Tk_GetPixelsFromObj converts the value of objPtr to the nearest even number of pixels and stashes it at *intPtr. under normal circumstances it returns TCL_OK. but if an error happens β like, say, objPtr holds a number followed by a character that isn't one of the ones above π β then TCL_ERROR comes back and an error message is left in interp's result, as long as interp isn't NULL. and because it's an overachiever, Tk_GetPixelsFromObj caches info about the return value in objPtr, which speeds up future calls to Tk_GetPixelsFromObj with that same objPtr. efficiency ate. π
Tk_GetDoublePixelsFromObj is identical to Tk_GetPixelsFromObj, except it returns a double β not rounded to the nearest integer. no rounding, all precision, that's the vibe. π
Tk_GetPixels is identical to Tk_GetPixelsFromObj, except the screen distance comes in as a string instead of an object. and because of that, it can't cache the return value, so Tk_GetPixels is less efficient than Tk_GetPixelsFromObj. ngl bestie, if you have the choice, take the object version. π«Ά
Tk_GetMMFromObj and Tk_GetScreenMM are similar to Tk_GetPixelsFromObj and Tk_GetPixels (respectively, matching them up like a cute little buddy system π§), except they convert the screen distance to millimeters and store a double-precision floating-point result at *doublePtr.
heads up: if you hand over a number with a unit character that isn't<none>,c,i,m, orp, you're gettingTCL_ERRORand an error message ininterp's result. no silent nonsense here. π
π KEYWORDS π
centimeters, convert, inches, millimeters, pixels, points, screen units β that's the whole tag list, slay β
and that's the page!! source is Tk, version 8.1, and the manual entry is Tk_GetPixelsFromObj(3tk). go forth and convert your units, bestie, you're gonna do amazing πβ¨ππ¦πΈπ
π«Ά
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1990 The Regents of the University of California
- Copyright (c) 1994-1998 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms