制作中のもの&理由
pythonで、Tkinterを使ってアラームを作っています。
ですが、ウィンドウを閉じる方法がわからず、投稿しました。
該当のソースコード(長いので一部)(雑)
python
1import tkinter as tk 2 3def settingseve11(): 4 messagebox.showinfo("情報", "設定を保存しました。(保存できていませんw)") 5 #ここに、roottを閉じるコードを書きたいです。 6 7# 設定ボタンを押したときの動作 8def pushed1(): 9 Val1 = tk.BooleanVar() 10 print("設定ボタンが押されました。") 11 roott = tk.Tk() 12 roott = roott 13 roott.title("設定") 14 roott.geometry("320x240") 15 labell = tk.Label(roott, text="アラームの設定") 16 labell2 = tk.Label(roott, text="チェックを入れるとONになります。") 17 labell3 = tk.Label(roott, text="チェックを入れてのON,OFF切り替えは現在できません。") 18 buttonn1 = tk.Button(roott, text="アラーム1の設定", command=seting1) 19 buttonn2 = tk.Button(roott, text="アラーム2の設定", command=seting2) 20 buttonn3 = tk.Button(roott, text="アラーム3の設定") 21 CheckBoxx = tk.Checkbutton(roott, text="アラーム1") 22 CheckBoxx2 = tk.Checkbutton(roott, text="アラーム2") 23 CheckBoxx3 = tk.Checkbutton(roott, text="アラーム3") 24 buttonn4 = tk.Button(roott, text="OK", command=settingseve11) 25 labell.pack() 26 labell2.pack() 27 labell3.pack() 28 buttonn1.pack() 29 buttonn1.pack() 30 buttonn2.pack() 31 buttonn3.pack() 32 CheckBoxx.pack() 33 CheckBoxx2.pack() 34 CheckBoxx3.pack() 35 buttonn4.pack() 36 37#終了ボタンが押された時の動作 38def pushed2(): 39 print("終了ボタンが押されました。") 40 sys.exit() 41 42#初めの画面 43root = tk.Tk() 44root.title("アラームGUI") 45root.geometry("230x100") 46 47label = tk.Label(root, text="アラーム PresentedBy mendoitarou_") 48button3 = tk.Button(root, text="開始", command=alarmstart, width=10) 49button = tk.Button(root, text="設定", command=pushed1, width=10) 50button2 = tk.Button(root, text="終了", command=pushed2, width=10) 51 52label.grid() 53button3.grid() 54button.grid() 55button2.grid() 56 57 58#初めの画面 ループ 59root.mainloop()
試したこと
python
1roott.destroy()
こちらを入力しましたが、閉じられませんでした。
エラーコード
Exception in Tkinter callback Traceback (most recent call last): File "D:\Users\mendo\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__ return self.func(*args) File "C:\Users\mendo\Desktop\アラーム\start.py", line 146, in settingseve11 roott.destroy() NameError: name 'roott' is not defined
補足情報(FW/ツールのバージョンなど)
Visual Studio Code
python 3.7.3
関係ない箇所は省いた上で、エラーが出ずに実行可能なコードにしてもらえると助かります。

回答2件
あなたの回答
tips
プレビュー