-1

I am using Python 3.7, and I am using tkinter to try and grid a widget in the middle of the screen. I don't want to use pack, because I still need to use grid for other widgets later. Is there a way to to grid the widget in the middle of the window?

martineau
  • 119,623
  • 25
  • 170
  • 301
Jerry Cui
  • 149
  • 7
  • You have to understand [what-does-weight-do-in-tkinter](https://stackoverflow.com/questions/45847313) – stovfl May 12 '20 at 21:06
  • Does this answer your question? [tkinter gui layout using frames and grid](https://stackoverflow.com/a/34277295/7414759) – stovfl May 12 '20 at 21:11

1 Answers1

1

This might not be the best solution, but one way is to essentially create an entire grid. In short, empty grid cells with some minimum width and then place the object in the centre-most grid box.

Something similar to this:

from tkinter import *

win = Tk()
for i in range(5):
    win.grid_rowconfigure(i, minsize=100)
    win.grid_columnconfigure(i, minsize=100)

lbl = Label(win, text="Test")
lbl.grid(row=2, column=2)

win.mainloop()

One thing to note is with this approach you might have to fidget with other widgets such as setting varying columnspans and rowspans during declaration.

Samay Gupta
  • 437
  • 3
  • 8