Python 在tkinter中使用replace()将文本输入从空格更改为-
这就是我想做的。我需要将所有空格从用户输入到“-”。因此,与其说“你好”,不如说“你好”。我试过很多不同的方法。我甚至试过Python 在tkinter中使用replace()将文本输入从空格更改为-,python,python-3.x,tkinter,str-replace,Python,Python 3.x,Tkinter,Str Replace,这就是我想做的。我需要将所有空格从用户输入到“-”。因此,与其说“你好”,不如说“你好”。我试过很多不同的方法。我甚至试过Text1=Text1.replace(“,“-”) 有人能帮我吗 您必须使用Text1获取当前文本。获取,替换内容并使用text更新。替换` Text1 = Text(root,height=1,width=15,background='grey') Text1.pack() Text1.replace(" ","-") 必须使用Text1获取当前文本。获取,替换内容并使
Text1=Text1.replace(“,“-”)
有人能帮我吗 您必须使用
Text1获取当前文本。获取
,替换内容并使用text
更新。替换`
Text1 = Text(root,height=1,width=15,background='grey')
Text1.pack()
Text1.replace(" ","-")
必须使用
Text1获取当前文本。获取
,替换内容并使用text
更新。替换`
Text1 = Text(root,height=1,width=15,background='grey')
Text1.pack()
Text1.replace(" ","-")
这就是你要找的吗 代码: Tkinter输出:
这就是你要找的吗 代码: Tkinter输出:
是的,就是这样。完美的非常感谢。我不知道我必须先给它下定义是的就是这样。完美的非常感谢。我不知道我必须先定义它,我也会试试这个。你能解释一下为什么是tkinter.END吗?我也会试试这个。你能解释一下为什么是tkinter.END吗?
from tkinter import *
def replace_space():
var = Text1.get('1.0','end')
var = str.replace(var, ' ', '-')
label['text'] = var
root = Tk()
Text1 = Text(root,height=1,width=15,background='grey')
Text1.pack()
button = Button(root, text = 'Go', command = replace_space)
button.pack()
label = Label(root)
label.pack()
root.mainloop()