0
votes

I am using Tkinter to code a GUI and I am running into a strange issue. I have specified my Root widget to be about 1/3rd of the screen width. However, when I create a Text widget within the root and specify its width to be the same value, it somehow takes more space than the available screen width. I know this because I resized the window and checked and also because title.winfo_reqscreen_width() is outputting 4130. That does not make sense since my screen resolution is 1440x900.

Here is the code I am using:

from tkinter import *

root = Tk()

app_width = int(root.winfo_screenwidth()/3.5)

root.geometry(f"{app_width}x{app_height}+0+0")
root.resizable(False, False)
root.pack_propagate(0)

title = Text(root, height=1, width=app_width, padx=10, pady=10, font=('NewComputerModern08', 18))
title.insert('1.0', 'Title')
title.bind("<Leave>", leave)
#title.grid(column=0, row=0, padx=5, pady=5)
title.pack()

I have also tried variations with pack_propagate(), grid(), fill=X, fill=BOTH, expand=True, and not adding a width argument to the widget etc. However, I am still facing the same issue.