在python tkinter中显示文件名
我目前正在从事一个翻译器项目,其中的输入将是一个文本文件,这是用英语创建的,我希望同样的翻译成德语。所以我使用askOpenFilename来查找要选择的文件,在选择文件后,文件的名称应该显示在标签按钮中。我如何在标签按钮中显示文件名?
选择 | 换行 | 行号
- import Tkinter as tk
- from tkFileDialog import askopenfilename
- import os
- class En2De(tk.Frame):
- def __init__(self,master=None):
- tk.Frame.__init__(self,master)
- self.grid()
- self.createWidgets()
- def createWidgets(self):
- self.quitButton = tk.Button(self, text='Quit',command=self.quit)
- self.UploadButton = tk.Button(self, text='UPLOAD FILES HERE',command= self.uploadButton)
- self.Label1=tk.Label(self)
- self.Label2 = tk.Label(self,text='Please Select a language:')
- optionlist = ('--Select--','Afrikaans','Albanian','English','French','German','Hindi','Tamil','Telugu')
- self.var=tk.StringVar()
- self.var.set(optionlist[0])
- self.om=tk.OptionMenu(self,self.var,*optionlist)#om=optionmenu
- #self.ConvertButton=tk.button(self, text'Convert Files',command=self.convertButton)
- #Registering it to the window
- self.quitButton.grid(sticky=tk.NE)
- self.UploadButton.grid()
- self.Label1.grid()
- self.Label2.grid()
- self.om.grid()
- def uploadButton(self):
- filename = askopenfilename(filetypes=(("Template Files","*.tplate"),("Portable Document File","*.pdf"),("Text File","*.txt"),("Word Document","*.docx"),("Word 97-2003 Document","*.doc"),("All Files","*.*")))
- Translater = En2De()
- Translater.master.title('A Translater for Translating Documents From English to German')
- Translater.mainloop()