python - Tkinter : Getting screen text unit width. (Not pixels) -
i'm using tkinter design ui application. i'm using grid geometry , while specifying button width (or widget width), realized width should specified in text units , not pixels. since want make platform independent , screen size independent there method max text unit width ? can math on basis of that.
for example:
i've 10 buttons in row, should of equal width. if hard code width value specific current screen value, not work on diff screen wise.
thanks.
if want make gui "platform independent , screen size independent", do not want measuring sizes yourself. unless, saying want platform independent, you're saying want button x pixels regardless of pixel density or screen resolution (which seems bad idea).
the whole reason tkinter supports measuring in character units, along options widgets stretch , shrink, support platform independence. when start working @ pixel level, have many, many problems when run code on other platforms, or on other displays, or other fonts.
that being said, measure
method of font can tell how many pixels given string require in given font. if want know how wide "one character" is, can use measure
method on string "0"
, tkinter uses base when computing widths based on characters.
if want buttons same size, using character widths give that, because isn't width of 10 actual characters in widget, ten average character widths. in case, "10 characters" same every widget, no matter contents of widget.
Comments
Post a Comment