简体   繁体   English

Tkinter中网格布局的访问位置

[英]Access position of grid layout in tkinter

Is there a quick way to access the location I placed certain widget. 是否可以快速访问我放置某些小部件的位置。

For example, if I have a button 例如,如果我有一个按钮

self.exampleButton = tk.Button(self)
self.exampleButton.grid(row=3,column=0,sticky="EW") 

Is there a way that I can get the row or column? 有没有一种方法可以获取行或列? Something like self.exampleButton.getPosition ? self.exampleButton.getPosition这样的self.exampleButton.getPosition

Is creating a dictionary to store the information, like {self.exampleButton:(3,0)} , the best way? 最好是创建一个字典来存储信息,例如{self.exampleButton:(3,0)}吗?

Tkinter has a handy grid_info() function: Tkinter有一个方便的grid_info()函数:

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

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

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