Get the with of the supplied string in pixels for the font being passed in. If an error occurs, 0 will be returned :param font: specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike,
(cls, font, string)
| 4320 | |
| 4321 | @classmethod |
| 4322 | def string_width_in_pixels(cls, font, string): |
| 4323 | """ |
| 4324 | Get the with of the supplied string in pixels for the font being passed in. |
| 4325 | If an error occurs, 0 will be returned |
| 4326 | :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 |
| 4327 | :type font: (str or (str, int[, str]) or None) |
| 4328 | :param string: the string to measure |
| 4329 | :type string: str |
| 4330 | :return: Width in pixels of string |
| 4331 | :rtype: (int) |
| 4332 | """ |
| 4333 | |
| 4334 | # A window must exist before can perform this operation. Create the hidden master root if it doesn't exist |
| 4335 | _get_hidden_master_root() |
| 4336 | |
| 4337 | size = 0 |
| 4338 | try: |
| 4339 | size = tkinter.font.Font(font=font).measure(string) # string's width |
| 4340 | except Exception as e: |
| 4341 | _error_popup_with_traceback('Exception retrieving string width in pixels', e) |
| 4342 | |
| 4343 | return size |
| 4344 | |
| 4345 | def _print_to_element(self, *args, end=None, sep=None, text_color=None, background_color=None, autoscroll=None, justification=None, font=None, append=None): |
| 4346 | """ |
nothing calls this directly
no test coverage detected