Get the with of the character "W" in pixels for the font being passed in or the character of your choosing if "W" is not a good representative character. Cannot be used until a window has been created. If an error occurs, 0 will be returned :param font:
(cls, font, character='W')
| 4272 | |
| 4273 | @classmethod |
| 4274 | def char_width_in_pixels(cls, font, character='W'): |
| 4275 | """ |
| 4276 | Get the with of the character "W" in pixels for the font being passed in or |
| 4277 | the character of your choosing if "W" is not a good representative character. |
| 4278 | Cannot be used until a window has been created. |
| 4279 | If an error occurs, 0 will be returned |
| 4280 | :param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike, to be measured |
| 4281 | :type font: (str or (str, int[, str]) or None) |
| 4282 | :param character: specifies a SINGLE CHARACTER character to measure |
| 4283 | :type character: (str) |
| 4284 | :return: Width in pixels of "A" |
| 4285 | :rtype: (int) |
| 4286 | """ |
| 4287 | # A window must exist before can perform this operation. Create the hidden master root if it doesn't exist |
| 4288 | _get_hidden_master_root() |
| 4289 | |
| 4290 | size = 0 |
| 4291 | try: |
| 4292 | size = tkinter.font.Font(font=font).measure(character) # single character width |
| 4293 | except Exception as e: |
| 4294 | _error_popup_with_traceback('Exception retrieving char width in pixels', e) |
| 4295 | |
| 4296 | return size |
| 4297 | |
| 4298 | @classmethod |
| 4299 | def char_height_in_pixels(cls, font): |
nothing calls this directly
no test coverage detected