|
发表于 2020-11-5 21:11:59
|
显示全部楼层
本楼为最佳答案
本帖最后由 qiuyouzhi 于 2020-11-5 21:13 编辑
这样行吗
- from tkinter import *
- def func():
- text = entry.get().replace(string, "")
- entry.delete(0, END)
- entry.insert(0, text)
- root = Tk()
- string = "BOCAI"
- entry = Entry(root, width = 20)
- entry.pack()
- button = Button(root, text = "Remove", width = 15, command = func)
- button.pack()
复制代码
这样也可以
- from tkinter import *
- def func():
- text = entry.get()
- start, end = text.find(string), text.find(string) + len(string)
- entry.delete(start, end)
- root = Tk()
- string = "BOCAI"
- entry = Entry(root, width = 20)
- entry.pack()
- button = Button(root, text = "Remove", width = 15, command = func)
- button.pack()
复制代码 |
|