如何在Tkinter的Canvas小部件中放置小部件? [英] How to place a widget in a Canvas widget in Tkinter?

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

问题描述

我希望基本上能够使用 Canvas 作为其他小部件的元容器。

I want basically to be able to use a Canvas as a meta container for other widgets.

我想将GUI分为左侧,中间和中间部分。在每个部分中,我希望能够放置小部件,例如: Checkbutton Button 标签,等等。

I want to divide my GUI into a left, center and middle section. Within each section I would like to be able to place widgets like: Checkbutton, Button, Label, etc.

如何在Canvas小部件中放置小部件?

How to place widgets in a Canvas widget?

推荐答案

您的选择取决于您真正要实现的目标。为什么使用画布比使用框架更好?

Your choices depend on what you're really trying to accomplish. Why is using a canvas preferable to using a frame?

您可以像使用包装盒,网格或放置容器一样轻松地将小部​​件添加到画布中。这样做时,滚动画布时这些项目将不会滚动,因为它们实际上并不是画布的一部分。

You can easily add widgets to a canvas just like you do any other container, using pack or grid or place. when you do this, the items will not scroll when you scroll the canvas because they aren't actually part of the canvas.

另一种选择是在窗口上创建窗口对象画布。您可以使用画布的 create_window 方法执行此操作。优点是,此窗口成为画布的一部分,并将与画布上的任何其他对象一起滚动。缺点是,您唯一的选择是绝对放置,您必须显式控制小部件的大小。

The other choice is to create window objects on the canvas. You do this with the create_window method of the canvas. The advantage is, this window becomes part of the canvas and will scroll along with any other objects on the canvas. The downside is, your only option is absolute placement and you have to explicitly control the size of the widgets.

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

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