在 Tkinter 的另一个小部件中调整一个小部件的大小

Resizing one widget inside another widget in Tkinter(在 Tkinter 的另一个小部件中调整一个小部件的大小)
本文介绍了在 Tkinter 的另一个小部件中调整一个小部件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为穆斯堡尔光谱(化学)开发一个模拟软件,但是在设计 UI 时,我在使用父小部件调整子小部件的大小时遇到​​了问题.当窗口最大化时,父框架会填充额外的空间,但子窗口小部件不会改变其大小.

I am developing a simulation software for Mössbauer spectroscopy (Chemistry) but while designing the UI, I am facing problem while resizing the children widget with parent widget. The parent frame fills the extra space when window is maximized but the children widget doesn't changes its size.

from Tkinter import *
import ttk
import tkFileDialog as FileDialog
from PIL import Image, ImageTk
import tkFont
import matplotlib
from numpy import sin, pi

root = Tk()
# Main Container
content = ttk.Frame(root)
bold = tkFont.Font(family='Helvetica', weight='bold')
LeftFrame = ttk.Frame(content, borderwidth=5, relief="groove", width=200)
RightFrame = ttk.Frame(content, borderwidth=5, relief="groove", width=750)
text = Text(LeftFrame, height=40, width=30, padx=5, pady=5)

..... Some Codes .....

# Geometry
LeftFrame.grid(column=0, row=1, rowspan=2, sticky=(N, S, E, W))
RightFrame.grid(column=1, row=1, columnspan=3, rowspan=2, sticky=(N, S, E, W))
namelbl.grid(column=0, row=1, sticky=(N, S, E, W), padx=5)
text.grid(column=0, row=2, sticky=(N, S, E, W))

root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
content.columnconfigure(0, weight=1)
content.columnconfigure(1, weight=3)
content.columnconfigure(2, weight=3)
content.columnconfigure(3, weight=3)
content.rowconfigure(1, weight=1)

root.state("zoomed")

root.mainloop()

所以,我的问题是如何以相同的速率更改 text 小部件(子级)和 LeftFrame(父级)的大小.在我的情况下,只有 LeftFrame 正在扩展,而 text 是恒定的.

So, my question is How do I change the size of text widget (children) with LeftFrame (parent) in the same rate. In my case only LeftFrame is expanding while text is constant.

推荐答案

您没有为框架内的小部件提供 sticky 选项,这会阻止小部件填充它们所在的区域给定的.此外,您没有给出内部框架行和列的权重.

You aren't giving the sticky option to the widgets inside the frame, which prevents the widgets from filling the area they have been given. Also, you aren't giving the inner frame rows and columns weights.

任何时候使用网格,都应该为父窗口小部件的行和列指定权重.如果您在框架内有框架,则每个框架都是独立的,并且需要适当配置其行和列.

Any time you use grid, you should be specifying weights for the rows and columns of the parent widgets. If you have frames inside of frames, each frame is independent and needs its rows and columns configured appropriately.

这篇关于在 Tkinter 的另一个小部件中调整一个小部件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)