Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

change default 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 :: how to 404 custom page not found in django 
Python :: python convert list of strings to list of integers 
Python :: how to run python file from cmd in dockerfile 
Python :: python files 
Python :: pynput.keyboard.Key 
Python :: Efficiently count zero elements in numpy array? 
Python :: time now random seed python 
Python :: state_dict() 
Python :: how to execute python program in ubuntu 
Python :: django sort descending 
Python :: IntegrityError import in django 
Python :: how to import flask restful using pip 
Python :: descending python dataframe df 
Python :: tkinter how to move button 
Python :: show multiple matplotlib images 
Python :: filter list of tuples python 
Python :: python append to csv on new line 
Python :: pandas dataframe column names 
Python :: how to delete a csv file in python 
Python :: python insert 
Python :: get list file in folder python 
Python :: python remove all unicode from string 
Python :: remove all instances from list python 
Python :: python reverse split only once 
Python :: how to fill a list in python 
Python :: python try then change something and try again if fails 
Python :: print column in 2d numpy array 
Python :: how to download the captions of a youtube video 
Python :: tkinter progressbar set value 
Python :: import sklearn.metrics from plot_confusion_matrix 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =