(Python3)- tkinter 執行結果後清除輸入框 (Entry) 的方法
(Python3)- tkinter 執行結果後清除輸入框 (Entry) 的方法
Method 1.
# -*- coding: utf-8 -*-
from tkinter import *
class App:
def __init__(self, root):
self.root = root
self.entry = Entry(self.root)
self.button = Button(root, text="Ok", command=self.command)
self.entry.pack()
self.button.pack()
def command(self):
self.entry.delete(0, END)
root = Tk()
App(root)
root.mainloop()
Method 2.
# -*- coding: utf-8 -*-
import tkinter as tk
class App(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master, height=42, width=42)
self.entry = tk.Entry(self)
self.entry.focus()
self.entry.pack()
self.clear_button = tk.Button(self, text="Clear text", command= self.clear_text)
self.clear_button.pack()
def clear_text(self):
self.entry.delete(0, 'end')
def main():
root = tk.Tk()
App(root).pack(expand=True, fill='both')
root.mainloop()
if __name__ == "__main__":
main()
Method 3.
# -*- coding: utf-8 -*-
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()
免責聲明:
1.本影像檔案皆從網上搜集轉載,不承擔任何技術及版權問題。
2.如有下載連結僅供寬頻測試研究用途,請下載後在24小時內刪除,請勿用於商業。
3.若侵犯了您的合法權益,請來信通知我們,我們會及時刪除,給您帶來的不便,深表歉意。