現状input_box.insertでテキストボックスに出力しても time.sleep(10) が終わるまで結果が表示されません。
本来は time.sleep(10)の所に色々処理を入れて途中でもテキストボックスを書き換えたいのですが、def file_select():が完了するまでテキストボックスが書き換えされません。
処理途中でもテキストボックス更新する方法が有りましたらご指導頂けないでしょうか。
よろしくお願いいたします。
Python
1import tkinter 2import time 3from tkinter import filedialog 4 5 6#ボタンがクリックされたら実行 7def file_select(): 8 idir = 'C:\\python_test' #初期フォルダ 9 filetype = [("テキスト","*.txt"), ("音楽","*.mp3"), ("すべて","*")] #拡張子の選択 10 file_path = tkinter.filedialog.askopenfilename(filetypes = filetype, initialdir = idir) 11 input_box.delete(0, tkinter.END) 12 input_box.insert(tkinter.END, file_path) #結果を表示 13 time.sleep(10) # 秒 14 15def file_select2(): 16 idir = 'C:\\python_test' #初期フォルダ 17 filetype = [("テキスト","*.txt"), ("音楽","*.mp3"), ("すべて","*")] #拡張子の選択 18 file_path = tkinter.filedialog.askopenfilename(filetypes = filetype, initialdir = idir) 19 input_box.insert(tkinter.END, file_path) #結果を表示 20 21#ウインドウの作成 22root = tkinter.Tk() 23root.title("Python GUI") 24root.geometry("600x240") 25 26#入力欄の作成 27input_box = tkinter.Entry(width=80) 28input_box.place(x=10, y=100) 29 30#ラベルの作成 31input_label = tkinter.Label(text="結果") 32input_label.place(x=10, y=70) 33 34#ボタンの作成 35button = tkinter.Button(text="参照",command=file_select) 36button.place(x=10, y=130) 37 38#ボタンの作成 39button = tkinter.Button(text="参照",command=file_select2) 40button.place(x=50, y=130) 41 42 43#ウインドウの描画 44root.mainloop()
回答1件
あなたの回答
tips
プレビュー