ステータス出力を表示するための簡単な情報ボックスが必要です。代わりに、を使用してコンソールにダンプしprint
ます。私が見つけた最も簡単な可能性は次のとおりです。
import Tkinter as tk
root = tk.Tk()
root.withdraw()
from tkMessageBox import showinfo
showinfo('some caption', 'some info')
この実装の唯一の問題は、メッセージボックスの「ok」ボタンが押されるまで、私のプログラム( Tkinterで書かれていない)が実行を継続しないことです。showinfo
つまり、showinfo
ダイアログはブロックされます。
したがって、私の質問:showinfo
ノンブロッキングを作成する簡単な方法はありますか?非ブロッキングであるTkinterの代替メッセージボックス実装はありますか?ヘルプページを表示する一般的な使用方法を考えることができます。ウィンドウが開き、メインプログラムが正常に実行され続けます。
編集1:これは私が思いついた簡単なヘルプウィンドウですが、別のtkMessageBox
または同様のオブジェクトを起動しない限り、残念ながら表示されません:
class TextInfo(object):
def __init__(self, parent, window_title = 'window', textfield = 'a text field', label = None):
self.top = tk.Toplevel(parent)
self.parent = parent
self.window_title = window_title
self.textfield = textfield
# set window title
if window_title:
self.top.title(window_title)
# add label if given
if label:
tk.Label(self.top, text=window_title).grid(row=0)
# create the text field
self.textField = tk.Text(self.top, width=80, height=20, wrap=tk.NONE)
if textfield:
self.textField.insert(1.0, textfield)
self.textField.grid(row=1)
# create the ok button
b = tk.Button(self.top, text="OK", command=self.ok)
b.grid(row=2)
def ok(self):
self.top.destroy()
そして、これは私がウィンドウを呼び出す方法です:
root = tk.Tk()
root.withdraw()
TextInfo(self.root, window_title, textfield, label)
# don't call root.mainloop() here, because this will lead to blocking.
ウィンドウを表示するために設定する必要のあるプロパティやイベントはありますか?呼び出すroot.mainloop()
とウィンドウが表示されますが、GUIが再びブロックされます。