Difference between “fill” and “expand” options for tkinter pack method

前端 未结 2 1253
一个人的身影
一个人的身影 2020-12-13 17:53

I know this is a too trivial question, but I am new to python, and I have just started using the tkinter module. I have actually looked up about it everywhere,

2条回答
  •  独厮守ぢ
    2020-12-13 18:18

    I'm done with trial and error ;-). Here is an overview.

    import tkinter as tk
    
    root = tk.Tk()
    root.geometry()
    
    for e, expand in enumerate([False, True]):
        for f, fill in enumerate([None, tk.X, tk.Y, tk.BOTH]):
            for s, side in enumerate([tk.TOP, tk.LEFT, tk.BOTTOM, tk.RIGHT]):
                position = '+{}+{}'.format(s * 205 + 100 + e * 820, f * 235 + 100)
                win = tk.Toplevel(root)
                win.geometry('200x200'+position)
                text = str("side='{}'\nfill='{}'\nexpand={}".format(side, fill, str(expand)))
                tk.Label(win, text=text, bg=['#FF5555', '#55FF55'][e]).pack(side=side, fill=fill, expand=expand)
                    
    root.mainloop()
    

提交回复
热议问题