ここでは初めての質問です。
Pythonもまだ習い始めたばかりです。(VBAやC#の経験はあります)
ダイアログベースのプログラム
(最初から最後までダイアログが表示されているようなプログラム)
の記述例はネット上にありましたので分かりましたが、
メインのプログラムから一時的にダイアログを表示して、
ダイアログが閉じられたら再びメインのプログラムに戻って、
処理を進めていくようなプログラムの基本的な書き方がよく分かりません。
具体的には、
Pythonのプログラムを実行すると、
- 実行条件を設定する設定ダイアログを表示して
ユーザーが実行条件の設定を完了したら開始ボタンで
この設定ダイアログを閉じる。 - 設定された実行条件に基づいてデータ処理を行い、
実行結果をファイルに出力する。
3) 処理が終了したことを示す終了ダイアログを表示して
ユーザーからの完了ボタンで
このダイアログを閉じてプログラムを終了する。
という処理を行いたいのですが、
以下のコードでは、
1)のユーザーの設定が終わる前に、
2)3)の処理が実行されてしまいます。
Python
1import tkinter 2import win32api 3 4#flg=0 5 6# 1) 開始処理 7root1=tkinter.Tk() 8root1.title('開始') 9root1.geometry('300x200') 10label1=tkinter.Label(root1,text='実行を開始します') 11label1.grid() 12button1=tkinter.Button(root1,text='開始',command=lambda : pushed1()) 13button1.grid() 14 15#while flg!=1: 16# print(flg) 17 18# 2) 本処理 19win32api.Sleep(10000) 20 21# 3) 終了処理 22root2=tkinter.Tk() 23root2.title('終了') 24root2.geometry('300x200') 25label2=tkinter.Label(root2,text='終了しました') 26label2.grid() 27button2=tkinter.Button(root2,text='完了',command=lambda : pushed2()) 28button2.grid() 29 30#while flg!=2: 31# print(flg) 32 33print('END') 34 35def pushed1(): 36# global flg 37# flg=1 38 root1.destroy() 39 40def pushed2(): 41# global flg 42# flg=2 43 root2.destroy()
1)で開始ボタンが押されるまで、2)以降の処理を実行しないようにするには、
どのように記述すればよいのでしょうか。できましたら、
グローバル変数を使用しない方法でお願いします。
(Windows10,Python 3.7.3)
【追記】
●list1
Python
1import tkinter 2import win32api 3 4def pushed1(): 5 root1.destroy() 6 7def pushed2(): 8 root2.destroy() 9 10#メイン処理 11 12# 1) 開始処理 13root1=tkinter.Tk() 14root1.title('開始') 15root1.geometry('300x200') 16label1=tkinter.Label(root1,text='実行を開始します') 17label1.grid() 18button1=tkinter.Button(root1,text='開始',command=lambda : pushed1()) 19button1.grid() 20 21root1.mainloop() 22 23# 2) 本処理 24win32api.Sleep(10000) 25 26# 3) 終了処理 27root2=tkinter.Tk() 28root2.title('終了') 29root2.geometry('300x200') 30label2=tkinter.Label(root2,text='終了しました') 31label2.grid() 32button2=tkinter.Button(root2,text='完了',command=lambda : pushed2()) 33button2.grid() 34 35root2.mainloop() 36 37print('END')
●list2
Python
1import tkinter 2import win32api 3 4def pushed1(): 5 root1.destroy() 6 7def pushed2(): 8 root2.destroy() 9 10#メイン処理 11 12# 1) 開始処理 13root1=tkinter.Tk() 14root1.title('開始') 15root1.geometry('300x200') 16label1=tkinter.Label(root1,text='実行を開始します') 17label1.grid() 18button1=tkinter.Button(root1,text='開始',command=lambda : pushed1()) 19button1.grid() 20root1.grab_set() 21root1.wait_window(root1) 22 23# 2) 本処理 24win32api.Sleep(10000) 25 26# 3) 終了処理 27root2=tkinter.Tk() 28root2.title('終了') 29root2.geometry('300x200') 30label2=tkinter.Label(root2,text='終了しました') 31label2.grid() 32button2=tkinter.Button(root2,text='完了',command=lambda : pushed2()) 33button2.grid() 34root2.grab_set() 35root2.wait_window(root2) 36 37print('END')
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/22 02:09 編集
2019/07/22 03:31
2019/07/22 06:38
2019/07/22 07:02
2019/07/22 07:15