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 8547 bvdet 2,851
Expert Mod 2GB
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
Expert Mod 2GB
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |