1

I'm converting a single language GUI into one that has to support multiple languages. The idea is when the user selects the "Language" radiobutton ALL everthing on the GUI immediately switches to the selected language. There’s no problem getting the python strings to update properly when the radiobutton changes butthe GUI won't update (switch languages).

The text strings (for all languages) and the code that switches between languages is isolated inside “LanguageInUse.py” (see below). Initial set up of the text/textvariable attribute of GUI objects is being done by invoking the associated .config() method immediately after (instead of during) object creation.

Dynamically modifying the text strings requires that "root" - the topmost GUI object - be an “application level global” (making it "read only" accessible in other modules). As per Python: How can I use variable from main file in module? "root" is created in its own file (tkinterRoot.py) making it importable by any module.
(BTW, “root” never changes after it has been created. So using an “application level” global avoids having to modify the existing code by adding a NEW, essentially useless parameter to EVERY call in the application’s call hierarchy which is implemented in many files.)

As per the “dirty solution” answer to Python tkinter: Update GUI between subprocess calls the call to root.update() - or root.update_idletasks() - is done immediately after the python strings are changed but the GUI does not change.

I’d prefer to use the “.configure()” approach (as per Bryan Oakleys answer to Getting Pyphons Tkinter to update a label with a changing variable) instead of StringVars and .update()/.update_idletasks().

What am I missing?

My environment is Win7 Enterprise SP1, Python 3.2.2 using Eclipse Mars (using portable java 8) and Pydev 4.5.5.

The following severely edited code fragments show the approach being used.

TkinterRoot.py (in it's entirety) :

from tkinter import Tk
root = Tk()

LanguageInUse.py :

import TkinterRoot

English  = 'English'                    # the default language
Francais = 'Fran' + "\u00E7" + 'ais'    # 00E7 = c_cedille in Win 7 character set
Espanol  = "Espanol"                    # not implemented

DefaultLanguage = Francais #Emulates the startup "argv" parameter

GUI_language = DefaultLanguage     # current GUI language (set by a radiobutton)

EmptyString  = ""

# Create every language dependent string as an “application level global” until
# a better approach is found.  (Don’t like a massive file containing the GUI 
# text in all languages but one thing at a time…  Worse is sprinkling the
# language change code throughout the many modules of the application.)

Title0 = EmptyString
Title1 = EmptyString
Title2 = EmptyString

def SetGuiLanguage( user_language ) :

    global Title0 
    global Title1
    global Title2

    if ( GUI_language == English ):
        Title0 = "Message Counts"
        Title1 = "Communications Compliance"
        Title2 = "Site Specific"  
    elif ( GUI_language == Francais ):
        Title0 = "Comtes de message"
        Title1 = "Compliance Communications"
        Title2 = "Spécifique du site"
    else:   # any other langauge
        System.exit() # dummy for other code

#    TkinterRoot.root.update()          # doesn't update GUI when language changes
    TkinterRoot.root.update_idletasks() # doesn't update GUI when language changes

'''-------------'''

# Sets up GUI text strings during initialization 

SetGuiLanguage( DefaultLanguage )  

The application mainline :

from tkinter import Tk, Toplevel, Frame, Button, N, W, E, S
from TkinterRoot import root
import LanguageOfUse

# Start of main program

LanguageInUse.SetGuiLanguage( LanguageInUse.GUI_language )

# Set up all GUI elements (includes the language selection radiobutton)

ConstructTheGui.ConstructTheGui( root )

root.mainloop()
Community
  • 1
  • 1
user1459519
  • 712
  • 9
  • 20

0 Answers0