如何在tkinter文本中删除通配符?

问题描述 投票:0回答:1

我想删除<>中的所有文本。我使用了replace('',''),但它根本没有删除它们。

例如,我的文字是check out here我希望它变成“ Nitin Hardeniya-2015-计算机”。

请告诉我如何纠正我的代码。

这里是代码:

import tkinter as tk

root = tk.Tk()
text = root.clipboard_get()
def onclick():
    text_widget.delete("1.0", "end")   
    text_widget.insert(tk.END, text.replace('<*>',' '))   

root = tk.Tk()
text_widget = tk.Text(root)
text_widget.insert(tk.END, text)  #inserting the data in the text widget
text_widget.pack()

button = tk.Button(root, text = "Press me!", command = onclick)
button.pack()

root.mainloop()
python-3.x tkinter wildcard
1个回答
0
投票

您需要使用正则表达式进行此类匹配。您行中的<*>text.replace('<*>',' ')不是正则表达式,它是严格匹配的内容(请参见replace函数文档)

© www.soinside.com 2019 - 2024. All rights reserved.