2

Im trying to find a way to center the window of a simple counter I made using Tkinter. Trying to find another way than using geometry I came across:

window.eval('tk::placeWindow . center')

But I don't know why this works and also I cant find it in the documentation. Anyone knows the answer?

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
Se7enBit
  • 23
  • 4
  • Does this answer your question? [How to center a window on the screen in Tkinter?](https://stackoverflow.com/questions/3352918/how-to-center-a-window-on-the-screen-in-tkinter) – oskros Nov 10 '22 at 13:27
  • 1
    The `tk::placeWindow` command is basically just calling the underlying C/Tk code, as you can see here: https://github.com/tcltk/tk/blob/master/library/tk.tcl#L72 – oskros Nov 10 '22 at 13:28
  • Im new to python and its really confusing... Why can I put it inside eval? – Se7enBit Nov 10 '22 at 13:34
  • 3
    It's not like a normal python eval - the eval you are calling is a method of the `window` Tk class, and as such its custom behavior is to pass on whatever you put there to the underlying `Tcl/Tk` engine – oskros Nov 10 '22 at 13:36

1 Answers1

5

The code below executes code that is written in tcl and calls a tcl procedure. There are quite a few of them, but they mostly used for internal procedures and rarely useful.

window.eval('tk::placeWindow . center')

The placeWindow procedure can be found here and does nothing that you couldn't do with python. They are most likely for maintainers that are used to tcl.

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54