LoginSignup
15
8

More than 5 years have passed since last update.

Tkinterメッセージボックス利用時の空ウィンドウ削除方法

Last updated at Posted at 2019-04-06

Pythonでメッセージボックスを出力する方法として、「tkinter」の「messagebox」を利用する方法がある。

例えば、

from tkinter import messagebox

messagebox.showerror("error", "can not execute process")

と書くと、

image.png

と出力される。
ただ、実はこれとは別に下図のような謎のウィンドウがもう1つ出力される。

image.png

これでは見栄えが良くない。

対策

下記のように、Tkinterのルートウィンドウを作成して非表示にしてしまう。

import tkinter as tk
root = tk.Tk()
root.withdraw()

どうやら、Tkinterはルートウィンドウを持たなければならず、ルートウィンドウがない場合、勝手に作成するらしい。
(他にいい方法があれば教えてください。)

参照

https://codeday.me/jp/qa/20190225/299233.html

15
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
8