Home > database >  Is there a function for repositioning the tkinter window using the from tkinter import * module?
Is there a function for repositioning the tkinter window using the from tkinter import * module?

Time:01-08

When my program runs, the tkinter window covers the output and a camera window, so I was wondering if I could reposition the window elsewhere.

I tried googling for this, but the solutions I found only worked if I used the from tkinter import tk or import tkinter as tk.They used a geometry function. I already have a lot of existing code based on the from tkinter import *, so I'm trying to find a way to move the window using the from tkinter import *.

CodePudding user response:

You need to call the geometry method of the root window. It doesn't matter how you import tkinter.

The geometry method takes a string of the form widthxheight x y and some variations. For example, you can do only widthxheight or only x y and you can use a - instead of .

For the complete description of the format see Geometry strings or the documentation for the wm geometry command in the official tcl/tk docs.

You can call this function as often as you like.

The following example makes a window 400 pixels wide, 200 tall, and located at position 100,300.

from tkinter import *

root = Tk()
root.geometry("400x200 100 300")

root.mainloop()
  • Related