在 tkinter 中,为什么 winfo

编程入门 行业动态 更新时间:2024-10-23 19:27:12
本文介绍了在 tkinter 中,为什么 winfo_height() 总是返回 1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

这是最简单的例子.

#py3从 tkinter 导入 *tk = tk()画布 = 画布(tk,宽度= 500,高度= 400)canvas.wininfo_height()#In [4]: canvas.winfo_height()#输出[4]:1

解决方案

你必须打包 在获取其高度之前窗口中的画布元素.返回的高度是实际高度.

<预><代码>>>>从 tkinter 导入 *>>>tk = tk()>>>画布 = 画布(tk,宽度= 500,高度= 400)>>>canvas.wininfo_height()1>>>画布.pack()>>>canvas.wininfo_height()402

This is the most easy example.

#py3
from tkinter import *
tk = Tk()
canvas = Canvas(tk, width= 500 , height = 400)
canvas.winfo_height()
#In [4]: canvas.winfo_height()
#Out[4]: 1

解决方案

You have to pack the canvas element in the window before getting it's height. The height return is the actual height.

>>> from tkinter import * 
>>> tk = Tk()
>>> canvas = Canvas(tk, width= 500 , height = 400)
>>> canvas.winfo_height()
1
>>> canvas.pack()
>>> canvas.winfo_height()
402

这篇关于在 tkinter 中,为什么 winfo_height() 总是返回 1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 08:38:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:tkinter   winfo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!