0% found this document useful (0 votes)
37 views1 page

161 - Solution

This document contains a Python function that selects a row from a list when an event occurs and displays the row's data in entry boxes. It uses a try/except block to prevent errors if no row is selected. The try block executes the row selection and entry box population normally. The except block contains a pass statement, so nothing happens if the selection fails due to an empty list.

Uploaded by

jd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views1 page

161 - Solution

This document contains a Python function that selects a row from a list when an event occurs and displays the row's data in entry boxes. It uses a try/except block to prevent errors if no row is selected. The try block executes the row selection and entry box population normally. The except block contains a pass statement, so nothing happens if the selection fails due to an empty list.

Uploaded by

jd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Solution

Section 13, Lecture 161


Solution
1. def get_selected_row(event):
2. try:
3. global selected_tuple
4. index=list1.curselection()[0]
5. selected_tuple=list1.get(index)
6. e1.delete(0,END)
7. e1.insert(END,selected_tuple[1])
8. e2.delete(0,END)
9. e2.insert(END,selected_tuple[2])
10. e3.delete(0,END)
11. e3.insert(END,selected_tuple[3])
12. e4.delete(0,END)
13. e4.insert(END,selected_tuple[4])
14. except IndexError:
15. pass

Explanation
As you can see the error was fixed by simply implementing a try and except block.
When the get_selected_row function is called, Python will try to execute the
indented block under try . If there is an IndexError none of the lines under try will
be executed. Instead the line under except will be executed which is pass .
The pass stetement means do nothing. So the function will do nothing when there's
an empty listbox.

Browse Q&A
Continue

You might also like