如何在 tkinter 中找出当前的小部件大小? [英] How to find out the current widget size in tkinter?

查看:36
本文介绍了如何在 tkinter 中找出当前的小部件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PythonTkinter,我需要知道小部件的当前尺寸(宽度、高度).

I'm using Python and Tkinter, and I need to know the current dimensions (width, height) of a widget.

我尝试过 somewidget["width"],但它只返回一个固定值,并且不会在小部件大小发生变化时更新(例如,当窗口调整大小时).

I've tried somewidget["width"], but it returns only a fixed value, and is not updated whenever the widget size changes (e.g. when the window is resized).

推荐答案

使用 somewidget.winfo_width()somewidget.winfo_height() 获取实际的小部件大小,somewidget['width'] 属性只是给几何管理器的一个提示.

Use somewidget.winfo_width() and somewidget.winfo_height() to get the actual widget size, the somewidget['width'] property is only a hint given to the geometry manager.

这篇关于如何在 tkinter 中找出当前的小部件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆