前提・実現したいこと
pythonでtkinterとkerasを用いたGUIをつくろうと思っています。
pythonでkerasをインポートする時間が長いので、インポートの間別のウィンドウを開いて、「ロード中」のような文字を表示させる処理をthreadingを使って作りたいのですが、うまくいきません。kerasのインポートの方は実行されているのですが、tkinterによるGUIの表示ができません。
発生している問題・エラーメッセージ
該当のソースコード
python
1import threading 2from threading import Thread 3import itertools 4import tkinter 5from tkinter import * 6import sys, time 7 8done = False 9 10def importkeras(): 11 global done 12 import keras 13 from keras.models import load_model 14 from keras.preprocessing.image import array_to_img, img_to_array,load_img 15 model = load_model(model_name + '.h5') 16 done = True 17 18def loading(): 19 global done 20 LoadAnimation = tkinter.Tk() 21 LoadAnimation.geometry("400x300") 22 23 LoadLabel = tkinter.Label(LoadAnimation, text="loading", width=400, font=("", 20)) 24 LoadLabel.pack() 25 26 #loadinganimation 27 for i in itertools.cycle(['.', '..', '...']): 28 if done: 29 LoadAnimation.destroy() 30 break 31 LoadLabel["text"] = "loading" + i 32 time.sleep(0.1) 33 34 LoadAnimation.mainloop() 35 36t1 = threading.Thread(target=importkeras) 37t2 = threading.Thread(target=loading) 38t1.start() 39t2.start() 40t1.join() 41t2.join() 42 43#この後にメインのウィンドウを表示させる 44root = tkinter.Tk() 45. 46. 47. 48
補足情報(FW/ツールのバージョンなど)
python 3.6.6
tkinter 8.6
あなたの回答
tips
プレビュー