Why tkinter don't throw/raise an exception?

后端 未结 1 317
闹比i
闹比i 2021-01-26 11:37

The problem is if you run this code below and resize the window then you will get unexpected behavior. Widgets are not rendered like they should and the backgrounds have some

相关标签:
1条回答
  • 2021-01-26 12:21

    @Idlehands Thanks for citing Fredrik Lundh's effbot.org explanation on background. I think I finally understand Fredrik Lundh's documentation. Namely,

    1. bg="" is a valid argument that will prevent the updating of the Frame widget's background, and
    2. the background or bg of a Frame widget defaults to the application background color.

    Hence, when the Tk window is resized, e.g. when the right edge of the Tk window is move to the left to reach the Canvas widget's right edge and followed by moving right back to its original position, the following phenomenon happens:

    1. Firstly, the Frame widget's width reduces in size. When this happens, I suspect the Tk widow background colour that filled the Frame widget is lost.
    2. Secondly, when the Frame widget's width next returns to its original size, it's background needs to be updated (i.e. filled) with a defined colour. Because bg="" prevents updating, i.e. prevents filling the Frame widget background with a defined background colour, the Frame widget's background will default to the "application background colour". Meaning it will be filled with the exact color of the area directly behind the Frame widget and the Tk window, as if it became 'transparent'.

    Answering @Turjak_art question, tkinter did not yield an Error or Exception because bg="" is a valid argument of the Frame widget.

    Edit:

    Image showing Frame background with fast resizing.

    Image showing Frame background with slow resizing.

    0 讨论(0)
提交回复
热议问题