What controls automated window resizing in Tkinter?

后端 未结 1 1247
长发绾君心
长发绾君心 2021-02-08 23:03

Tkinter top level windows seem to have two \"modes\": where the size is being determined by the application, and where the user controls the size. Consider this code:

         


        
1条回答
  •  长发绾君心
    2021-02-08 23:30

    The rule is pretty simple - a toplevel window has a fixed size whenever it has been given a fixed size, otherwise it "shrinks to fit".

    There are two ways to give the top level window a fixed size: the user can resize it manually, or your application code can call wm_geometry to give it a size at startup.

    To reset the original behavior, give the window a null geometry. For example:

    def __init__(self,parent):
        ...
        self.b2 = Button(self, text="Reset", command=self.b2Press)
        self.b2.pack()
    
    def b2Press(self):
        self.winfo_toplevel().wm_geometry("")
    

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