2

I am writing a program in python (3.8.1) tkinter and I am trying to make a full-width frame, but whenever I use methods on the root to get the width, it returns 1x1+320+180, but by looking at my code you can see that it's not the expected result (640).

from tkinter import *

root = Tk()

root.config(bg='#c0c0c0', relief=RAISED, bd=2) #sets background colour and stuff
root.attributes("-topmost", True) #stay on top
root.overrideredirect(1) #remove border
root.geometry('640x400+320+180') #set size of window
...
rootWidth = str(root.winfo_width()) #get size of window <<< ERROR HERE

print(root.wm_geometry())
  • 1
    The reason why you are getting `1x1+320+180` is that the window is not getting updated, use `root.update()` after `root.geometry('640x400+320+180')` to update the geometry before `mainloop()` runs. – Saad May 15 '20 at 09:20

1 Answers1

2

You forgot to add update() in your code.

Try this:

from tkinter import *

root = Tk()

root.config(bg='#c0c0c0', relief=RAISED, bd=2) #sets background colour and stuff
root.attributes("-topmost", True) #stay on top
root.overrideredirect(1) #remove border
root.geometry('640x400+320+180') #set size of window
root.update()
rootWidth = str(root.winfo_width()) #get size of window <<< ERROR HERE

print(root.wm_geometry())

Hope It Helps!

Ayush Raj
  • 294
  • 3
  • 14