私は、ユーザーがいくつかのファイルを選択して、オプションなどをマークするメインのtkinterウィンドウを持っています。 Runボタンを押すには、3つの事が起こる必要があります。Tkinterメインループブロッキング効果
- をメインウィンドウが
- 背景proccesを消え、新しいウィンドウが表示され、(で実行中のプロセスに関する情報を印刷するために開始し
- 中に実行を開始例:bは3、bは5、bは10など
2つのスレッドを使用せずにこれを行う方法はありますか(もしそうなら、どのように試みましたか?どのようにプロセスを終了するか)GUIとプロセスから1つ。私が知る限り、tkinter mainloopブロッキング効果を有する。 アドバイスをいただきありがとうございます。 次のコードは明らかになります。各ウィンドウにクラスがあります。
import tkinter as Tk
import time
class Mainframe(object):
def __init__(self,parent):
self.root=parent
self.root.title("Main frame")
self.frame=Tk.Frame(parent)
self.frame.pack()
btn=Tk.Button(self.frame,text="Run momma",command=self.RunButton)
btn.pack()
def Secondwindow(self):
self.root.destroy()
newWindow=Tk.Tk()
window=Secondframe(newWindow)
def process(self):
b=0
for a in range(0,20):
b=a
print (b)
time.sleep(0.2)
def RunButton(self):
self.Secondwindow()
self.process()
class Secondframe(object):
def __init__(self,parent):
self.root=parent
self.root.title("Main frame")
self.frame=Tk.Frame(parent)
self.frame.pack()
self.root.geometry("400x300")
self.root.title("otherFrame")
if __name__=="__main__":
root=Tk.Tk()
root.geometry("800x600")
app=Mainframe(root)
root.mainloop()
ブリリアント!ありがとう。私は非常にプログラミングに新しいし、すべての内部を知っていない、例えば、なぜあなたは一度も何度もtk()を呼び出すべきではない。私はまた、後のメソッドを使用するように見えましたが、私は一度だけ実行させる方法を理解できませんでした。とにかく、答えのためのthxは、これを理解することに私を多く助けるだろう:D – Mike