回答編集履歴
1
ソースコードの追記
test
CHANGED
@@ -92,6 +92,80 @@
|
|
92
92
|
|
93
93
|
---------------------------
|
94
94
|
|
95
|
+
__2016/9/22 9:27 追記__
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
import tkinter as tk
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
BASE0_DEAD = False
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
def countdown(count):
|
112
|
+
|
113
|
+
global BASE0_DEAD # グローバル変数のBASE0_DEADを呼び出すと明示的に指示しています。
|
114
|
+
|
115
|
+
if not BASE0_DEAD:
|
116
|
+
|
117
|
+
base0.destroy()
|
118
|
+
|
119
|
+
BASE1_DEAD = True
|
120
|
+
|
121
|
+
if count > 0:
|
122
|
+
|
123
|
+
label.configure(text=count)
|
124
|
+
|
125
|
+
count -= 1
|
126
|
+
|
127
|
+
base1.after(1000, lambda :countdown(count)) #tkinterのTkクラスにはタイマーが内蔵されているらしく、それを利用して再帰呼出しさせています。
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
if count == 0:
|
132
|
+
|
133
|
+
base1.destroy()
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
if __name__ == '__main__': # このスクリプトが直接実行された際には以下を実行するように。と書いて、メインの処理と関数を分割して見やすくしたつもりです。
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
base0 = tk.Tk() ###ここで選択ウィンドウを作成
|
144
|
+
|
145
|
+
button = tk.Button(base0, text='start 60', command=lambda :countdown(60))
|
146
|
+
|
147
|
+
button.pack()
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
base1 = tk.Tk() ###ここでカウントダウンウィンドウを作成
|
152
|
+
|
153
|
+
label = tk.Label(base1)
|
154
|
+
|
155
|
+
label.pack()
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
base0.mainloop()
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
```
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
---------------------------
|
168
|
+
|
95
169
|
|
96
170
|
|
97
171
|
参考資料
|
@@ -99,3 +173,5 @@
|
|
99
173
|
* [プログラミング FAQ — Python 3.5.2 ドキュメント](http://docs.python.jp/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value)
|
100
174
|
|
101
175
|
* [お気楽 Python/Tkinter 入門](http://www.geocities.jp/m_hiroi/light/pytk01.html)
|
176
|
+
|
177
|
+
* [python - How to create a timer using tkinter? - Stack Overflow](http://stackoverflow.com/questions/2400262/how-to-create-a-timer-using-tkinter)
|