Tkinter:为什么添加标签会水平扩展框架?

时间:2018-07-23 17:40:45

标签: python-3.x tkinter

下面链接的第一个屏幕截图是我需要两个框架的尺寸。当我添加标签(屏幕截图2)时,标签似乎会扩展框架本身,因此不遵循原始尺寸。

如何在不修改left_frame本身大小的情况下添加标签?

Before Adding Text

After Adding Text

import tkinter as tk

# Window
root = tk.Tk()
root.geometry("1280x720")
root.title("NMR Pulse Sequence Generator")
root.resizable(width="FALSE", height="FALSE")

# Frames
left_frame = tk.Frame(root, background="white", width=10, height=100)
right_frame = tk.Frame(root, background="#f2f2f2", width=10, height=100)

left_frame.grid(row=0, rowspan=2, column=0, sticky="nsew")
right_frame.grid(row=0, rowspan=2, column=1, sticky="nsew")

root.grid_columnconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=3)
root.grid_rowconfigure(0, weight=1)
root.grid_rowconfigure(1, weight=1)

# UI
main_title = tk.Label(left_frame, text="NMR Pulse Sequence Generator", font="Courier", pady=20)
main_title.pack()

root.mainloop()

0 个答案:

没有答案