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? -
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()
-
5 8550 bvdet 2,851
Recognized Expert Moderator Specialist
There are more that one way. Here's one: - self.Label1.config(text="the_file_name")
@bvdet
Thank you for your help. It is working,but I want only the filename not the full path. And initially it should display 'No files uploaded' in red colour. If the file is updated it must display a file name in some colour(Green). How can I do it any ideas ?
@bdvet
Please refer line no 26. - self.Label1.config(text=filename, fg="blue")
I tried it. Is it the correct way to do ?
bvdet 2,851
Recognized Expert Moderator Specialist
Option fg or foreground specifies the color of the text. Yes, that would be the correct way.
To display the file name only: - >>> import os
-
>>> path = r"D:\SDS2_7.3B\plugins\SagRod\SagRod.py"
-
>>> os.path.basename(path)
-
'SagRod.py'
-
>>>
To display an initial message in red: - w = Tkinter.Label(parent, text="No files uploaded", fg="red")
@bdvet
I had tried the following to display the filenames within a label
The first method is to display full path and the filename -
self.Label1.config(text=filename, fg="blue")
The second way is to display only the filename -
self.Label1.config(text=os.path.basename(filename), fg="blue")
both seems to be working.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Leo |
last post by:
hi there
for somebody who wants tostart small/medium GUI apps with python:
what's the best toolkit: tkinter, wxPython or what? stability, ease of use
and portability between mac and windows...
|
by: Mickel Grönroos |
last post by:
Hi everybody,
I'm using QuickTimeTcl (3.1) to be able to play movie files in my Tkinter
application (Python 2.3.2) on Windows 2000. I was planning to write a
simple wrapper class,...
|
by: SteveFerrigno |
last post by:
Ok, firstly I’m really sorry if this is in the wrong place :( but anyway. I have created a program which I want to convert into a .exe so I use PY2EXE but even if I have saved the python file I...
|
by: John Chambers |
last post by:
Sp my latest adventure is attempting to use python's Tkinter module on a few machines.
On my PB (OSX 10.3.9), I got the following confusing results:
/Users/jc: python
Python 2.3 (#1, Sep 13...
|
by: dabrowsa |
last post by:
I'm working on a simple Python program, with Tkinter, and I need to display the math symbols for set union and interesection, in unicode \N{N-ARY UNION} and \N{N-ARY INTERSECTION}. Everything was...
| |
by: sj |
last post by:
I am just learning to use Tkinter and am having problems displaying image
files. I am able to display an image using tutorials (such as
http://www.daniweb.com/code/snippet296.html) But when I try...
|
by: Hendrik van Rooyen |
last post by:
Hi,
I get the following:
hvr@LINUXBOXMicrocorp:~/Controller/libpython display.py
UpdateStringProc should not be invoked for type font
Aborted
and I am back at the bash prompt - this is...
|
by: ShambhuHubli |
last post by:
Hi !
I am developing front end for some application using Python Tkinter. And I am new to this GUI development.
In my application, I have to create buttons other than square or rectangle. I want...
|
by: ShambhuHubli |
last post by:
Hi all !
I am developing GUI in Python Tkinter for one application.
In this I have created one Text box. And I need to insert the text inside the text box directly in to some paticular line...
|
by: alivip |
last post by:
How to brows and select a directory of file by using python TKinter
like brows to find attachment in email
but I can select not only file but whole directory
any help
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |