2012-08-15 8 views

Respuesta

7

¡Lo tengo!

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

La forma en que depura el problema también puede ser útil para otras personas necesitadas:

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')} 

Así que después de buscar en ese conjunto completo de configuraciones supuse que era o bien el punto culminante o parámetro closeenough.

+0

Puede confirmar visualmente esta respuesta utilizando este ejemplo: [link] (http://stackoverflow.com/a/11894636/1217270). Puede ver un borde fino de color gris claro, que desaparece cuando agrega 'highlightthickness = 0'. –

0

Porque los métodos winfo_reqwith() y winfo_reqheight() no devuelven el ancho y la altura reales de un widget. Esto es lo que dice la documentación:

winfo_reqheight(), winfo_reqwidth(). 

Volver la altura "natural" (anchura) para el auto. El tamaño natural es el tamaño mínimo de necesario para mostrar el contenido del widget, incluido el relleno, bordes, etc.. Este tamaño se calcula por el widget en sí, en función de las opciones dadas. El tamaño del widget real se determina luego por el administrador de geometría del widget, basado en este valor, el tamaño del maestro del widget y las opciones dadas al administrador de geometría.

+1

No veo cómo responde esto a la pregunta. Creo que la persona que pregunta sabe qué devuelve 'winfo_reqwidth', ellos están preguntando _por qué _ devuelve algo diferente al ancho y alto solicitados. –

Cuestiones relacionadas