Want to find tkinter window grid locatiion

the code which i given below i just want to know the exact location of row and column and also want to know how many rows and column are there so i can place my widget at specific location that i want after knowing this =

from tkinter import *

window = Tk()

window.title(“Caesar_cipher”)

window.config(padx=100, pady=100)

Labels

message_label = Label(text="Message: ")

Entries

message_entry = Entry(width=15)

message_entry.focus()

Buttons

encode_button = Button(text=“encode”, width=10, highlightthickness=0)

window.mainloop()

I’ve not coded many Tkinter apps, but this is my understanding, which may or may not be flawed…

There is no ‘exact location’, as you put it: the location of one widget, on a ‘x’ ‘y’ grid, will depend on the location of another widget being on the same grid.

If you .grid(row=0, column=0) a widget, and it’s the only widget, it will be centered in the containing widget (say, your window, for example).

Now for your second widget, if you .grid(row=0, column=1) it will be to the right of the first one, which will shift left, so that both are relative center in the containing widget.

You may want to plan ahead when numbering the rows and columns. For example, the second widget may be .grid(row=0, column=10) which will look exactly the same as before, but now you have the option (should you need to) to use any of the columns between 1 and 9 for a widget (or widgets) that you may want in the future, without having to change the column numbers of the already coded widgets: coding a third widget with .grid(row=0, column=5) for example, will ‘grid’ the third one between the first two.

Have a read of:

2 Likes

Thank you for your help sir.

You’re welcome.

There are, of course, other Geometry Controls, but with ‘Grid’ (and some planning) it can be a quicker way to put a GUI together.

For a quick and simple GUI, I use EasyGui, which (I think) has Tkinter ‘under the hood’, so to speak.

1 Like

The following tool is also quite convenient:

1 Like