473,573 Members | 2,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change menu text with Tkinter?

I am making a little Tkinter GUI app that needs to be in several
languages (english, french, etc.), adjustable at runtime via a menu
pick to select the language. The only way I can see to change text in
the menus entries is to destroy them and recreate them usiing different
labels. This seems very clunky though, and there must be a better way.
Can anyone offer any pointers or a short example for how to do this?

Thanks,
Phil

Sep 27 '06 #1
5 5048
In <11************ **********@d34g 2000cwd.googleg roups.com>, Phil Schmidt
wrote:
I am making a little Tkinter GUI app that needs to be in several
languages (english, french, etc.), adjustable at runtime via a menu
pick to select the language. The only way I can see to change text in
the menus entries is to destroy them and recreate them usiing different
labels. This seems very clunky though, and there must be a better way.
Can anyone offer any pointers or a short example for how to do this?
Do you really need this at runtime or is it enough to store the language
in a config file and ask the user to restart the application? Then using
the `gettext` module is a good way. Maybe in combination with the
`locale` module so you can use the language of the operating system as
default if the user doesn't choose one explicitly.

Ciao,
Marc 'BlackJack' Rintsch
Sep 27 '06 #2

Phil Schmidt wrote:
I am making a little Tkinter GUI app that needs to be in several
languages (english, french, etc.), adjustable at runtime via a menu
pick to select the language. The only way I can see to change text in
the menus entries is to destroy them and recreate them usiing different
labels. This seems very clunky though, and there must be a better way.
Can anyone offer any pointers or a short example for how to do this?
Try this:

menu.entryconfi g(index, label="new_name ")

HTH,
Rob

Sep 27 '06 #3
On Wed, 27 Sep 2006 15:29:32 +0200, Phil Schmidt
<ph************ *****@yahoo.com wrote:
I am making a little Tkinter GUI app that needs to be in several
languages (english, french, etc.), adjustable at runtime via a menu
pick to select the language. The only way I can see to change text in
the menus entries is to destroy them and recreate them usiing different
labels. This seems very clunky though, and there must be a better way.
Can anyone offer any pointers or a short example for how to do this?
Here is a way:

------------------------------------------------------------------
from Tkinter import *

root = Tk()
mb = Menu(root)
root.configure( menu=mb)
fm = Menu(mb)
mb.add_cascade( label='File', menu=fm)

def chlg():
mb.entryconfigu re(1, label='Fichier' )
fm.entryconfigu re(1, label='Changer de langue')
fm.entryconfigu re(2, label='Quitter' )

fm.add_command( label='Change language', command=chlg)
fm.add_command( label='Quit', command=root.qu it)

root.mainloop()
------------------------------------------------------------------

Note that the entry indices start at 1 because of the 'tearoff' entry that
is always created in a menu. If you specify the option tearoff=0 when
creating the menus, indices will start ot 0.

But Marc's answer still applies: it's a lot of work for something that
will usually be configured once. So requiring to restart the tool when the
UI language changes should be acceptable.
Thanks,
Phil
HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Sep 27 '06 #4

Eric Brunel wrote:

>
But Marc's answer still applies: it's a lot of work for something that
will usually be configured once. So requiring to restart the tool when the
UI language changes should be acceptable.
Thanks for the example, that helps.

I agree with you and Marc regarding the language configuration method.
The requirements aren't mine however - my customer wants the language
selectable at runtime, so I'm kind of stuck with that.

Phil

Sep 27 '06 #5
Phil Schmidt wrote:
Eric Brunel wrote:
>But Marc's answer still applies: it's a lot of work for something that
will usually be configured once. So requiring to restart the tool when the
UI language changes should be acceptable.

Thanks for the example, that helps.

I agree with you and Marc regarding the language configuration method.
The requirements aren't mine however - my customer wants the language
selectable at runtime, so I'm kind of stuck with that.
You might also explain to the customer that of any menu elements are
ordered alphabetically, the result of changing the language will be
jarring to the user, as well as expensive to implement.

--Scott David Daniels
sc***********@a cm.org
Oct 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5962
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual...
3
1356
by: Adonis | last post by:
I wish to create a popup menu from a list, when it is created they all show the same label from the list: Months = def _Menu_Click(self, month): print month menu = Menu(fraMain, tearoff=0)
1
5356
by: eltronic | last post by:
here is some code to add right click context menus. in the few apps I've edited sofar, it just works, once you run rCbinder with the root of the gui or bind B3 all present and future widgets will have right click. there will be a line something like root=Tk.mainloop() #or Tkinter.mainloop() in epydoc it was necessary to look into the gui...
1
6235
by: Martin | last post by:
Anybody know how to change the menu button that is displayed by the Tkinter Menubutton and the (derived from it) OptionMenu classes? I think it must be something from the Motif look and feel which doesn't fit with my appl which is designed primarily for running on Windows and OS X. The default button visual that appears is basically a small...
1
6777
by: Philippe C. Martin | last post by:
Hi, I have he following need and do not find an easy way out: I have many menu items and would like them all to call the same method -However, I need the method called to react differently depending on the menu item selected. Since the menu command functions do not seem to receive any type of event style object, is there some type of...
2
2404
by: gh14tq5 | last post by:
Hi, I'm writing a small GUI program in Python/Tkinter (my first Python program). I want to make a menu which lists the names of a number of text files that my program uses/generates. When I select one of the files from the menu, I would like a new window to open up a scroll box containing the file. I was able to get it to work by hard a...
2
2830
by: ishtar2020 | last post by:
Hi everybody I'd appreciate some help on creating a tear off menu with TkInter. I've been reading some documentation but still no luck. Please don't get confused: when I mean "tear off" menu I don't mean a drop-down or a pop-up menu, but those options which yield to another batch of sub-options when scrolled over, (as for example, the...
4
1954
by: Edward K. Ream | last post by:
Hello all, Creating a 'Help' menu 'by hand' on the Mac does not work, or rather, it creates a *second* Help menu. There are hints about how to do this at:
0
1082
Elias Alhanatis
by: Elias Alhanatis | last post by:
Hello everybody , I have the following piece of code ( please dont pay any attention to the Greek... :-) ) , and i would like to know if there is a way to make the menu under each MenuButton appear only by entering its space with the mouse ( and thus saving some million clicks from the users....). I think i've seen this kind of thing elsewhere...
0
7741
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7661
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7978
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8167
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7730
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6349
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5550
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5252
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2164
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 we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.