Trouble using Tkinter grid

前端 未结 1 1395
醉话见心
醉话见心 2020-12-12 07:24

I am completely new to Tkinter and I am having problems in placing the widgets where I want them to be. I have been through numerous posts here, but I can\'t really find a w

相关标签:
1条回答
  • 2020-12-12 07:57

    So what I do when I want to have "Displays" is to create a frame in frame and define the innerframe with width and height.

    As exampel:

    import tkinter as tk
    
    root=tk.Tk()
    holderframe = tk.Frame(root,bg='red')
    innerframe = tk.Frame(holderframe, width=300, height=300)
    
    holderframe.grid()
    innerframe.grid()
    root.mainloop()
    

    I'm not absolut sure if the following is true, but based on my memory of reading the tkinter docs, I will explain:

    Somewhere is written that tkinter calculates the width and height automatically by the space it needs to place the widgets.

    Following this logic it means that the inner widget is predefining the outer ones. So by configure the innerframe(width=300, height=300) the outer frame needs to be at least this big and it spans automatically.

    How does this help ?

    For you, you could define your displays first and make them a bit bigger as your widgets. This way you can place them how you like and they will not messed up by update.

    More

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