我有一个文件列表,我希望能够搜索他们的名字并使用Tkinter中的Entry功能打开它们。问题是,我需要能够从Tkinter条目中删除空格字符。到目前为止,这是我的代码:
import os
import sys
from tkinter import *
master = Tk()
Label(master, text=">").grid(row=0)
name = Entry(master)
name.grid(row=0, column=1)
def openFile():
os.system("nautilus "+name.get())
Button(master, text='Search', command=openFile).grid(row=3, column=1, sticky=W, pady=4)
mainloop( )
我需要在输入栏中输入任何空格。
我尝试过在任何地方都使用这种方法:
for char in ' ':
name = name.replace(char,'')
但这也不起作用。我到处研究过但却找不到任何东西,大概是因为它有多具体。
有谁知道我怎么能这样做?
答案 0 :(得分:0)
这应该有效:
import os
import sys
from tkinter import *
master = Tk()
Label(master, text=">").grid(row=0)
x=StringVar()
name = Entry(master,textvariable=x)
name.grid(row=0, column=1)
def openFile():
y=x.get()
y.replace(" ","")
os.system("nautilus "+y)
Button(master, text='Search', command=openFile).grid(row=3, column=1, sticky=W, pady=4)
mainloop( )
希望这会有所帮助..