Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How to check which Button was clicked in Tkinter ?
Next article icon
Prerequisites:Python GUI – tkinterThe Listbox widget is used to display a list of items from which a user can select a number of items. But have you ever wondered, how to return the list of possible results when a key is pressed? Let's see the following approach towards the same.Working of Program
  • List consisting of words is initialized.
  • Entry box and Listbox are created and are added to the root window.
  • Bind function is used for event handling. Key release event is handled for an Entry field.
  • When any key is pressed in the Entry,checkkey() function is called.
  • checkkey() function then compares the entered string with existing list keywords and populates Listbox with matching keywords.
  • Then this data is sent to update function which then updates the Listbox.
Below is the approach.Python 1==
fromtkinterimport*# Function for checking the# key pressed and updating# the listboxdefcheckkey(event):value=event.widget.get()print(value)# get data from lifvalue=='':data=lelse:data=[]foriteminl:ifvalue.lower()initem.lower():data.append(item)# update data in listboxupdate(data)defupdate(data):# clear previous datalb.delete(0,'end')# put new dataforitemindata:lb.insert('end',item)# Driver codel=('C','C++','Java','Python','Perl','PHP','ASP','JS')root=Tk()#creating text boxe=Entry(root)e.pack()e.bind('<KeyRelease>',checkkey)#creating list boxlb=Listbox(root)lb.pack()update(l)root.mainloop()
Output:python-listbox

Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp