Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change selected option optionmenu tkinter

"""
Change selected option optionmenu tkinter.
If at any time you change the value of the variable, it will update your widget.
"""

import tkinter as tk # First we import tkinter as tk

root = tk.Tk() # We then create the root
optionList = ('a', 'b', 'c') # And a list for the selections
v = tk.StringVar() # Then create a stringvar
v.set(optionList[0])  # Here is the initially selected value (we set the stringvar to optionlist[0], aka choose the "a")
om = tk.OptionMenu(root, v, *optionList) # Create the optionmenu
om.pack() # Pack it

v.set(optionList[2]) # This one will be the final selected value("c"), you can change the number to 1 or 0 to fit your needs.
root.mainloop() # And mainloop

"""
FYI, the numbering starts from 0, so to select "a" you need to change the varaible to "0"
"""
Comment

PREVIOUS NEXT
Code Example
Python :: python dataframe remove header 
Python :: iterate over list and select 2 values together python 
Python :: create virtual env 
Python :: with urllib.request.urlopen("https:// 
Python :: comparing two dataframe columns 
Python :: python procedured 
Python :: python import multiple csv 
Python :: pyodbc sql save pandas dataframe 
Python :: How to find xpath by contained text 
Python :: how to print palindrome in 100 between 250 in python 
Python :: dataframe fill none 
Python :: reset django database 
Python :: find order of characters python 
Python :: bot wait_for discord py 
Python :: prevent list index out of range python 
Python :: python print class variables 
Python :: pyspark check all columns for null values 
Python :: index of max in tensor 
Python :: python input lowercase 
Python :: plotly line plot 
Python :: Python make directories recursively 
Python :: what is python used for 
Python :: left click pyautogui 
Python :: how to hide a turtle in turtle python 
Python :: how to practise python 
Python :: python loop through array step size 2 
Python :: pandas groupby aggregate multiple columns 
Python :: video streaming flask 
Python :: set size of button tkinter 
Python :: python continue 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =