Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Tkinter canvas request 4 extra pixels for the width and height?

Tags:

python

tkinter

tk

>>> import Tkinter
>>> c = Tkinter.Canvas(width=100, height=100)
>>> c.winfo_reqwidth()
104
>>> c.winfo_reqheight()
104

The results are the same if I set borderwidth to zero. I can't find the setting or property that explains or controls these 4 extra pixels.

like image 710
ubershmekel Avatar asked Aug 15 '12 18:08

ubershmekel


1 Answers

Got it!

c = Tkinter.Canvas(width=100, height=100, highlightthickness=0)
>>> c.winfo_reqwidth()
100

The way I debugged the problem may also be useful to others in need:

import pprint
pprint.pprint(c.configure())
{'background': ('background',
                'background',
                'Background',
                'SystemButtonFace',
                'SystemButtonFace'),
 'bd': ('bd', 'borderWidth'),
 'bg': ('bg', 'background'),
 'borderwidth': ('borderwidth', 'borderWidth', 'BorderWidth', '0', '0'),
 'closeenough': ('closeenough', 'closeEnough', 'CloseEnough', '1', '1.0'),
 'confine': ('confine', 'confine', 'Confine', '1', '1'),
 'cursor': ('cursor', 'cursor', 'Cursor', '', ''),
 'height': ('height', 'height', 'Height', '7c', '100'),
 'highlightbackground': ('highlightbackground',
                         'highlightBackground',
                         'HighlightBackground',
                         'SystemButtonFace',
                         'SystemButtonFace'),
 'highlightcolor': ('highlightcolor',
                    'highlightColor',
                    'HighlightColor',
                    'SystemWindowFrame',
                    'SystemWindowFrame'),
 'highlightthickness': ('highlightthickness',
                        'highlightThickness',
                        'HighlightThickness',
                        '2',
                        '0'),
 'insertbackground': ('insertbackground',
                      'insertBackground',
                      'Foreground',
                      'SystemButtonText',
                      'SystemButtonText'),
 'insertborderwidth': ('insertborderwidth',
                       'insertBorderWidth',
                       'BorderWidth',
                       '0',
                       '0'),
 'insertofftime': ('insertofftime', 'insertOffTime', 'OffTime', '300', '300'),
 'insertontime': ('insertontime', 'insertOnTime', 'OnTime', '600', '600'),
 'insertwidth': ('insertwidth', 'insertWidth', 'InsertWidth', '2', '2'),
 'offset': ('offset', 'offset', 'Offset', '0,0', '0,0'),
 'relief': ('relief', 'relief', 'Relief', 'flat', 'flat'),
 'scrollregion': ('scrollregion', 'scrollRegion', 'ScrollRegion', '', ''),
 'selectbackground': ('selectbackground',
                      'selectBackground',
                      'Foreground',
                      'SystemHighlight',
                      'SystemHighlight'),
 'selectborderwidth': ('selectborderwidth',
                       'selectBorderWidth',
                       'BorderWidth',
                       '1',
                       '1'),
 'selectforeground': ('selectforeground',
                      'selectForeground',
                      'Background',
                      'SystemHighlightText',
                      'SystemHighlightText'),
 'state': ('state', 'state', 'State', 'normal', 'normal'),
 'takefocus': ('takefocus', 'takeFocus', 'TakeFocus', '', ''),
 'width': ('width', 'width', 'Width', '10c', '100'),
 'xscrollcommand': ('xscrollcommand',
                    'xScrollCommand',
                    'ScrollCommand',
                    '',
                    ''),
 'xscrollincrement': ('xscrollincrement',
                      'xScrollIncrement',
                      'ScrollIncrement',
                      '0',
                      '0'),
 'yscrollcommand': ('yscrollcommand',
                    'yScrollCommand',
                    'ScrollCommand',
                    '',
                    ''),
 'yscrollincrement': ('yscrollincrement',
                      'yScrollIncrement',
                      'ScrollIncrement',
                      '0',
                      '0')}

So after looking at that full set of configurations I guessed it was either the highlight or closeenough parameter.

like image 83
ubershmekel Avatar answered Oct 15 '22 10:10

ubershmekel