2016-12-03 72 views
1

是否有快速访问我放置特定窗口小部件的位置的方法?在tkinter中访问网格布局的位置

举例来说,如果我有一个按钮

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

有没有办法,我能得到的行或列?像self.exampleButton.getPosition

正在创建一个字典来存储信息,比如{self.exampleButton:(3,0)},最好的方法是什么?

回答

1

的Tkinter有一个方便的功能grid_info()

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