[tkinter] Window lost focus after certain codes

Here is an example showing how a window lost its focus after some codes. Is it a bug or normal phenomenon?
Thanks anyone’s help.
Plus, my environment: win10, tkinter8.6.12 & tkinter 8.6.13

import tkinter
from tkinter import ttk 
root = tkinter.Tk()
entry = ttk.Entry(root)
entry.grid()
entry.focus_set()
root.state('withdrawn')
root.update()
root.resizable(False, False)
root.resizable(True, True)
root.state('normal')
root.mainloop()

I ran it in IDLE, the window created didn’t get focus.

I don’t know whether it’s a bug, but I don’t understand why you’re doing this:

root.state('withdrawn')
root.update()
root.resizable(False, False)
root.resizable(True, True)
root.state('normal')

it’s not a bug and why would you do that?.. what @MRAB is curious about. There’s alot going on here you are reducing the window size, resizing then not resizing and then returning to normal … what was your aim?

I am pretty sure that withdrawing root and making it invisible necessarily gives up focus.

It is a condensed code to concentrate on problem. Of course the actual codes doesn’t look like this, but they are the same essentially.

Thank you for letting me know that withdrawing and making it visible gives up focus, then how do I make it get focus again?

Get rid of the unneeded root calls or more entry.focus_set().

More ‘entry.focus_set()’ doesn’t work. Now I use ‘iconic’ instead of ‘withdrawn’ cooperating with ‘entry.focus_force’, it works well.