Tkinter simpledialog boxes not getting focus in Windows 10 with Python3

Viewed 1651

In the code below, the first dialog box gets focus immediately, so the user can just type an answer and press enter. In the second one, that doesn't seem to happen when running in Windows. Running Raspbian 9, both windows get focus when they open.

Is there any way I can get both windows to get focus when they open in Windows?

import tkinter as tk
from tkinter import simpledialog

root = tk.Tk()
root.withdraw()

answer1 = simpledialog.askstring("Test1","This one gets focus when it opens",parent=root)
answer2 = simpledialog.askstring("Test2","This one doesn't",parent=root)
1 Answers

I have watched this question for a few days now hoping someone might shed some light on this issue. I'm running Python 3.6.5 under windows 10 and get the same problem.

I have tried several different things but it seems Microsoft does things their own way. I have finally found a thing that works, but only if you don't hide the root window:

import tkinter as tk
from tkinter import simpledialog

root = tk.Tk()
#root.withdraw()     # This does not work if you hide the root window

root.update_idletasks()
answer1 = simpledialog.askstring("Test1","This one gets focus",parent=root)

root.update_idletasks()
answer2 = simpledialog.askstring("Test2","This one doesn't",parent=root)
Related