在 tkinter 中显示网格布局单元格 [英] Show grid layout cells in tkinter

查看:51
本文介绍了在 tkinter 中显示网格布局单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有技巧在使用时显示网格布局单元格(或单元格的边框),以便直观地了解幕后发生的事情?>

我已经搜索了一点,但还没有找到.

解决方案

如果您为包含框架指定颜色,并使用选项在单元格之间放置填充,背景将通过间隙渗出.这仅适用于有小部件的地方.如果您有空的跨度,您将看不到网格线.

重要的是要意识到您不是在创建网格对象.网格"不是一个东西,它只是关于如何布置一组小部件的说明.如果行或列中没有任何内容,则不会显示该列.您本身并不创建网格,而是告诉小部件使用概念行和列显示内部小部件.

学习使用网格的另一个技巧是为您尝试在网格中使用的每个帧指定独特的颜色,以便您可以看到一个帧的结束位置和另一个帧的开始位置.

遇到布局问题时,最好的办法就是拿出铅笔和纸.画出你的用户界面,自然边框应该很明显.然后,您可以使用它作为指南来决定网格选项应该是什么.

Is there a trick to show the grid layout cells (or the borders of the cells) when using it, in order to have a visual idea of what is going on behind the scenes?

I have searched a little bit, but have not found nothing yet.

解决方案

If you give the containing frame a color, and use options to put padding between cells, the background will bleed through the gaps. This only works where there are widgets. If you have spans that are empty, you won't see grid lines.

It's important to realize that you aren't creating a grid object. "grid" is not a thing, it's just instructions for how to lay out a set of widgets. If there is nothing in a row or column, that column won't show up. You don't create a grid per se, you tell a widget to display inner widgets using conceptual rows and columns.

Another trick to learning to work with grid is to give each frame you're trying to use in a grid a distinctive color so you can see where one frame ends and another begins.

The best thing to do when struggling with a layout is to get out pencil and paper. Draw out your UI, and natural borders should be evident. You can then use that as a guide to decide what the grid options should be.

这篇关于在 tkinter 中显示网格布局单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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