2017-02-28 33 views
1

RE:Toplevelの存在を確認するToplevel()オブジェクトがtkinterに存在するかどうかを確認しますか?

ランダムな母音をランダムに作成するかランダムな子音をランダムに作成するかを選択する15秒の制限時間を設定しています手紙のリスト。 (私は他の人の回答から得たGUIタイマーを含むToplevelを使用しています)。

時間通りに管理していれば、類似のタイマーがORIGINALウィンドウに表示され、母音/子音ボタン(この時点では破壊されています)が置き換えられ、古いSEPARATEウィンドウのトップレベルタイマーが破棄されます。しかし、私は30秒後に開始する必要があるので、ユーザーがまだ文字を選択している間に、背景(VOWEL/CONSONANTボタンの後ろ)を刻むのではなく、適切なタイミングで開始する必要があるため、2回目のカウントダウンを行います。

これが意味をなさない場合、これは動作しないコードの基本的な概要です。

# I tried to test if the the Toplevel timer had been destroyed (which happens as soon as the 
# user has finished with the 9 letters). If so, I could then start the NEW 30-second timer. 

import tkinter as tk 

root = tk.Tk() 

test = tk.Label() 


# above: later, will test if a Label() widget counts as a 'child'. If it was the case 
# that only Toplevels counted as 'children', then I could have used the 'root.winfo_children' 
# command to test if the Toplevel() timer had been destroyed, in which case I can start a new 
# 30-second timer on the original window. 

test.pack() 

extraWindow = tk.Toplevel(root) 

extraWindow.destroy() # for below, to TRY and test whether the Toplevel object is destroyed 

if not root.winfo_children(): 
    print("N0") # doesn't happen, because test label is also a 'child' 
    # IMAGINE that this is where I set off the NEW 30-second timer 

root.mainloop() 

は残念ながら、私はそれが拳15秒で発症すると文字のリストを表示し、元のウィンドウ上のラベルを持っており、ユーザーはそれらの文字などの多くの実際の言葉を考え出すされている間新しい、30秒で可能です。 winfo_childrenは使用できません。私はwinfo_Toplevelの効果に何かできますか?

(EDIT:はいあり;は、私はようやく私の宿題をやったと私は見逃していたことは本当に明らかに何かを発見したので、残念ながら、私は自分の質問に答え)

答えて

2

私はちょうど私の答えを見つけたおっと自分の質問。 トップレベルが存在するかどうかは 'tkinter.Toplevel.winfo_exists(my_toplevel_name)'で確認できます。

これをprintステートメントに入れると、存在する場合は1を返し、存在しない場合は0を返します。

関連する問題