Tkinter テキストボックスの内容を削除する方法
Jinku Hu
2020年6月25日
2020年4月1日
Tkinter
Tkinter Text

Tkinter Text ウィジェットには、delete(first, last=None)
メソッドがあり、first
のインデックス、またはテキストボックスから (first, last)
の範囲内の文字を削除します。
last
が指定されていない場合、first
の位置で指定された文字のみが削除されます。
Tkinter テキストウィジェットのコンテンツをクリアするコード例
import tkinter as tk
root = tk.Tk()
root.geometry("400x240")
def clearTextInput():
textExample.delete("1.0","end")
textExample=tk.Text(root, height=10)
textExample.pack()
btnRead=tk.Button(root, height=1, width=10, text="Clear",
command=clearTextInput)
btnRead.pack()
root.mainloop()
textExample.get("1.0", "end")
"1.0"
と"end"
は、Text
ウィジェットのコンテンツの最初の文字と最後の文字を指します。Text
ウィジェットの入力を取得する方法の記事で紹介されているものと同じです。
Author: Jinku Hu
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn