在tkinter中访问网格布局的位置

5
有没有快捷的方法可以访问我放置某些小部件的位置。
例如,如果我有一个按钮。
self.exampleButton = tk.Button(self)
self.exampleButton.grid(row=3,column=0,sticky="EW") 

有没有一种方法可以获取行或列?例如像self.exampleButton.getPosition这样的方式?

创建一个字典来存储信息,像{self.exampleButton:(3,0)}这样的方式是最好的吗?

1个回答

6

Tkinter有一个方便的grid_info()函数:

info = exampleButton.grid_info()
print((info["row"], info["column"]))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接