擅长:python、mysql、java
<p>如果希望在<code>browseCSV()</code>中选择文件后更新标签,则需要将<code>StringVar</code>与标签关联,然后在<code>browseCSV()</code>中更新它:</p>
<pre><code>class application():
def __init__(self):
self.root = Tk()
self.csvFilename = StringVar() # use instance variable
...
Label(frameCSV, textvariable=self.csvFilename, bg='white').grid(row=1, column=1)
...
def browseCSV(self):
filename = filedialog.askopenfilename(initialdir="/Volumes/", title="select the file",
filetypes=[("CSV files", ".csv"),("all files", "*.*")])
if filename:
# a filename is selected, so update the label via StringVar
self.csvFilename.set(filename)
</code></pre>