我有一个框架,我固定了使用 grid_propagate() 方法的大小。我想在这个框架内居中放置一个框架。我该怎么办?
最佳答案
包装它以填充所有方向。根据需要添加填充。
或者,使用 place 可以让您使用相对或绝对定位。您可以使用 .5/.5 的相对 x/y 和“c”(中心)的 anchor 。
import Tkinter as tk
root=tk.Tk()
f1 = tk.Frame(width=200, height=200, background="red")
f2 = tk.Frame(width=100, height=100, background="blue")
f1.pack(fill="both", expand=True, padx=20, pady=20)
f2.place(in_=f1, anchor="c", relx=.5, rely=.5)
root.mainloop()
关于python - 如何在 Tkinter 的框架内居中放置框架?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4241036/