What is the correct syntax for accessing the 'x' and 'y' values in the 'place' attribute of a TKinter Checkbutton? I'm not finding anything to help in the docs and my attempts to guess the syntax haven't worked.
from tkinter import *
window=Tk()
v1 = IntVar()
arCombo = []
C1 = Checkbutton(window, state = "normal", text = "Ctrl", variable = v1)
C1.place(x=275, y=65)
arCombo.append(C1)
# these two successfully retrieve 'text' and 'state':
print(arCombo[0].cget("text"))
print(arCombo[0].cget("state"))
# How to access 'x' & 'y' values in 'place'?
# None of these work:
print(arCombo[0].cget("x"))
print(arCombo[0].cget("place"))
print(arCombo[0].place.cget("x"))
print(arCombo[0].place("x"))
window.title('Title')
window.geometry("800x600+10+10")
window.mainloop()
You can call the method
place_infoon a widget that was laid out usingplace. When called, it will return a dictionary that contains all of the information about all of the values used to place the window.In your case, the dictionary looks like this:
You can then query the value in the dictionary as you would with any dictionary. For example, you can print out the x coordinate like so:
Note: the values in the dictionary are all strings. If you want to treat the values as integers you must explicitly convert them to integers.