![tkinter winfo x position tkinter winfo x position](https://i.stack.imgur.com/Fq18p.png)
The placement of each button is defined by x and y. In this example, place () is used to position buttons based on x,y coordinates in a frame: We’ll draw three buttons. The y variable aligns buttons vertically. The x variable aligns buttons horizontally. Msg = Message(top, justify="center", text=_doc_).grid() place () has two options you can use: x and y. To convert that to absolute screen coordinates you can get the winfopointerxor winfopointery, and from that subtract the respective winforootxor winforooty For example: root tk. Top.geometry(self.windows_to_center(0,0)) Mouse Position Python Tkinter At any point in time you can use the method winfopointerxand winfopointeryto get the x,y coordinates relative to the root window. If True, execute all X server commands synchronously, so that errors are reported. Main_menu.add_cascade(label='Справка',menu=second_item) Running python -m tkinter from the command line should open a window. I am ready to listen to any criticism on my code. Where did I make a mistake? Previously, I used a procedural approach and did not observe such an error. I also apply this function to the Toplevel help window in the about function, in this case, the center position is set when setting the width and height, and without setting these parameters, the widget is not centered, it is located a little further from the center.
![tkinter winfo x position tkinter winfo x position](https://zetcode.com/img/gui/tkinter/simple.png)
![tkinter winfo x position tkinter winfo x position](https://i.stack.imgur.com/qZPbz.png)
In this case, the position of the window will always be in the center. Input data: width and height, if set to zeros, the window size will depend on the content.
#Tkinter winfo x position code
There is a code in which the main window of the program is automatically centered (the windows_to_center function).