How to set the position of a Tkinter window without setting the dimensions?


Tkinter windows are executed after initializing the object of the Tkinter frame or window. We can define the size of the Tkinter window or frame using the Geometry manager. It defines the width and height of the initial Tkinter window where we generally place our widgets. To set the position of the Tkinter window while omitting the width and height, we can define the specification in the geometry manager.

Example

# Import the required Libraries
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame
win = Tk()

# Set the geometry of tkinter frame without specifying width and height
x = 500
y = 300
win.geometry("+%d+%d" %(x,y))

# Add a Label widget
label = Label(win, text=" Tkinter has a variety of inbuilt functions, " "modules, and packages.", font = ('Georgia 20'))
label.pack(pady=10)

win.mainloop()

Output

Run the code to display a window that is set to its content width and height.

Updated on: 19-Jun-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements