Create four pull-down menus, and the list contents of the second pull-down menu change depending on the acquired value of the first pull-down menu. Do this with all four pull-down menus.
In the example, "upper body, lower body" is stored in the first pull-down menu, and when the upper body is selected, "head, chest, belly" can be selected in the second pull-down menu. If i select the head from the second pull-down menu, you will be able to select "mouth, eyes" from the third pull-down menu. I want to pass the value of the pull-down menu to the later pull-down menu continuously.
I can get the list of up to the second pull-down menu, but I can't get the list from the third pull-down menu
Corresponding source code
#Get list by selecting pull-down menu (1st)
def cb2_selected (event):
var1 = cb1.get ()
if var1 =='upper body':
val1 = ('head','chest','belly')
elif var1 =='lower body':
val1 = ('leg')
else: else:
val1 = ('')
cb2 = ttk.Combobox (main_win, state ='readonly')
cb2 ['value'] = val1
cb2.grid (row = 1, column = 1)
#Get list by selecting pull-down menu (second)
def cb3_selected (event):
var2 = cb2.get ()
if var2 =='head':
val2 = ('mouth','eye')
elif var2 =='chest':
val2 = ('chest','arms')
elif var2 =='belly':
val2 = ('navel')
elif var2 =='legs':
val2 = ('peach','ashi')
else: else:
val2 = ('')
cb3 = ttk.Combobox (main_win, state ='readonly')
cb3 ['value'] = val2
cb3.grid (row = 1, column = 2)
#Get list by selecting pull-down menu (third)
def cb4_selected (event):
var3 = cb3.get ()
if var3 =='mouth':
val3 == ('teeth')
elif var3 =='eyes':
val3 = ('pupil')
elif =='chest':
val3 = ('')
elif var3 =='arm':
val3 = ('hand','finger')
elif var3 =='navel':
val3 = ('')
elif var3 =='peach':
val3 = ('')
elif var3 =='feet':
val3 = ('finger')
else: else:
val3 = ('')
cb4 = ttk.Combobox (main_win, state ='readonly')
cb4 ['value'] = val3
cb4.grid (row = 1, column = 3)
#Pull-down menu binding settings
cb1.bind ('<<ComboboxSelected >>', cb2_selected)
cb1.bind ('<<Return >>', cb2_selected)
cb2.bind ('<<ComboboxSelected >>', cb3_selected)
cb2.bind ('<<Return >>', cb3_selected)
cb3.bind ('<<ComboboxSelected >>', cb4_selected)
cb3.bind ('<<Return >>', cb4_selected)
What I tried
In the previous post, there was a question that the list contents of the second pull-down menu change depending on the acquired value of the first pull-down menu, and I created this program with reference to it, but it worked well. I did not go.
It seems that the value of cb2 could not be obtained by get (), but the cause is unknown.
Execution environment
Windows 10
Python 3.8.5
-
Answer # 1
Related articles
- python 3x - change font size for python3 tkinter entry
- i want to dynamically change the value of a variable in python and execute it
- python - pltshow does not run unless you close the tkinter window
- i want to output the entry result of tkinter with python
- python - how to change the page to redirect when submitting depending on the value selected in the pull-down in the form
- python 3x - tkinter i want to write code concisely
- python - reopening the file dialog in tkinter results in an error
- python 3x - i want to change the background color of the specified line in python3 tkinter treeview
- python - i want to change the ip address that the django app gets by default from remote_addr to http_x_forwarded_for in middlew
- python 3x - python3 tkinter treeview data update
- i want to change the default version of python
- python - tkinter photo image question
- python 3x - unintended behavior of python3 tkinter binding
- python - [tkinter] [py installer] unable to execute exe file
- python - does pixel information change when cv2imwrite processing is performed?
- python 3x - change row name/column name of csv file
- python3 tkinter i want to be able to input only character strings in a fixed format
- python 3x - python3 tkinter toplevel behaves differently than intended
- i want to see the change of one element of a recurrence formula including a python matrix
- Python Tkinter not seeing 'TimePL' instance of Label widget
- python : How can a scrollbar be attached to a label in tkinter
- python : Why root.attributes('-topmost', False) fires every other time?
- python : How to write functions for buttons to work?
- Working buttons in TKinter in Python in OOP
- python : How to create a large text input field?
- python : How to keep the scale of buttons, text, etc in tkinter?
- python : how to bind keyboard input in Tkinter
- python : how to find out the size of a Tkinter window?
- python : How to make txt to html text converter
This is because the cb2 Combobox is created in a local variable inside each function.
The global variable cb2 in another function points to another widget.
I don't know where it is because I think it is out of the range of the code posted, but
Since it is cb2.bind, if you are making a widget somewhere globally,
This can be solved by creating the widget only the first time.
In each function, for widgets that have already been generated
Change only the value of the item.