Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:15:33+00:00 2026-05-24T20:15:33+00:00

I am using Python and Tkinter. I have an option menu with three choices

  • 0

I am using Python and Tkinter. I have an option menu with three choices with “on” being one of them. I want to make “on” be green when I select it. I don’t mean the font. I want the background of the option menu to be green when I select “on” while the other options will just be default gray.

How can I do this? I’ve seen other posts that just make the whole option menu background a different color, but I only want color when a particular choice is selected. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:15:36+00:00Added an answer on May 24, 2026 at 8:15 pm

    file this under U, for ugly:

    from Tkinter import *
    
    OPTIONS = (
        "egg",
        "go",
        "spam"
    )
    
    controlsMap = {}
    
    root = Tk()
    
    def callbackFunc(name, index, mode):
        value = root.getvar(name) #getvar: return the value of Tcl variable NAME
        widget = controlsMap[name]
        if value == 'go':
            widget.config(bg='green',fg='black',
                     activebackground='green',
                     activeforeground='black')
        else:
            widget.config(bg='SystemButtonFace',fg='SystemButtonText',
                     activebackground='SystemButtonFace',
                     activeforeground='SystemButtonText')
    
    
    var1 = StringVar(root, name='var1') #give it a master and a name
    var1.set(OPTIONS[0])
    om1 = OptionMenu(root, var1, *OPTIONS)
    om1.config(width=5)
    om1.grid(row=0, column=0)
    controlsMap['var1'] = om1
    var1.trace_variable('w', callbackFunc)
    
    var2 = StringVar(root, name='var2') #
    var2.set(OPTIONS[0])
    om2 = OptionMenu(root, var2, *OPTIONS)
    om2.config(width=5)
    om2.grid(row=0, column=1)
    controlsMap['var2'] = om2
    var2.trace_variable('w', callbackFunc)
    
    var3 = StringVar(root, name='var3') #
    var3.set(OPTIONS[0])
    om3 = OptionMenu(root, var3, *OPTIONS)
    om3.config(width=5)
    om3.grid(row=0, column=2)
    controlsMap['var3'] = om3
    var3.trace_variable('w', callbackFunc)
    
    
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple GUI in Python using the Tkinter library. This GUI
I have a python based tkinter script which executes some commands using subprocess module.
I'm working on a project using Tkinter and Python. In order to have native
I'm using Python Tkinter and I want to place a variable number of text
I'm using Python and tkinter . I have a Canvas widget that will display
I have a problem in Python. I'm using Tkinter and have four bind events,
Using Python I want to be able to draw text at different angles using
Using Python's Imaging Library I want to create a PNG file. I would like
Using Python, I want to know whether Java is installed.
Using Python, how does one parse/access files with Linux-specific features, like ~/.mozilla/firefox/*.default ? I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.