简体   繁体   English

如何获取 tkinter 中 columnconfigure 的权重?

[英]How to get the weights of columnconfigure in tkinter?

I want to get the weights of all the grid columns in a frame and apply the same weights to a different frame with the same number of columns.我想获取框架中所有网格列的权重,并将相同的权重应用于具有相同列数的不同框架。

If you call columnconfigure while only passing a column index, it will return a dictionary with all of the configuration values for that column.如果在仅传递列索引时调用columnconfigure ,它将返回包含该列所有配置值的字典。 You can loop over each column to get the weight and apply it to the other frame.您可以遍历每一列以获取权重并将其应用于另一帧。

The following example assumes you have 6 columns.以下示例假设您有 6 列。 Frame f1 has already been configured, and f2 should be given all of the same weights as f1 .框架f1已经被配置,并且f2应该被赋予与f1相同的权重。

for column in range(6):
    weight = f1.grid_columnconfigure(column)['weight']
    f2.grid_columnconfigure(column, weight=weight)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM