2016-12-03 39 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"]))