私はTkinterを使用して2つのウィンドウを構築しています。主なものの1つであるボタンを押すと、2番目のウィンドウが作成されます。
この2番目のウィンドウは、作成時にすぐにはフォーカスされません。.focus_force()を呼び出すことで修正できます。ただし、tkFileDialogからaskdirectory()関数を呼び出すと、フォーカスが最初のウィンドウに戻ります。
どこでもfocus_force()を呼び出すだけで、フォーカスの切り替えが発生しないようにするにはどうすればよいですか?
問題を再現するには:
from Tkinter import *
from tkFileDialog import *
class app:
def __init__(self, master):
Button(master, command = make_new).grid()
def make_new(self):
root = Tk()
new = new_win(root)
root.mainloop() #here the focus is on the first window
class new_win:
def __init__(self, master):
f = askdirectory() #even after placing focus on second window,
#focus goes back to first window here
Python2.7.3を使用しています。ありがとう!