I am currently working on a translator project, in which the input will be a text file, that is created in English and I want the same to be translated to German. So I have used askopenfilename to look for files to be selected after selecting the file the name of the file should be displayed in the label button.How do I display the file name within the label button is that possible?
Code:
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()
Comment