2012-08-15 36 views

Trả lời

7

OK!

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

Con đường tôi sửa lỗi vấn đề cũng có thể hữu ích cho những người khác có nhu cầu:

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

Vì vậy, sau khi xem xét rằng tập hợp đầy đủ các cấu hình tôi đoán nó là một trong hai điểm nhấn hoặc tham số closeenough.

+0

Bạn có thể xác nhận bằng trực quan câu trả lời này bằng cách sử dụng ví dụ sau: [link] (http://stackoverflow.com/a/11894636/1217270). Bạn có thể thấy một đường viền màu xám nhạt hơn, biến mất khi bạn thêm 'highlightthickness = 0'. –

0

Vì phương thức winfo_reqwith()winfo_reqheight() không trả về chiều rộng và chiều cao thực tế của tiện ích. Đây là những gì tài liệu nói:

winfo_reqheight(), winfo_reqwidth(). 

Return sự "tự nhiên" height (chiều rộng) cho bản thân. Kích thước tự nhiên là kích thước tối thiểu là cần thiết để hiển thị nội dung của tiện ích, bao gồm đệm, đường viền, v.v.. Kích thước này được tính bởi chính tiện ích, dựa trên các tùy chọn đã cho. Kích thước tiện ích thực tế sau đó được xác định bởi hình dạng của tiện ích con người quản lý, dựa trên giá trị này, kích thước của tiện ích con và tùy chọn được cung cấp cho trình quản lý hình.

+1

Tôi không thấy cách này trả lời câu hỏi. Tôi nghĩ rằng người hỏi sẽ biết những gì 'winfo_reqwidth' trả về, họ đang yêu cầu _why_ nó trả về một cái gì đó khác với chiều rộng và chiều cao yêu cầu. –

Các vấn đề liên quan