from tkinter import *
from tkinter import ttk

class Searchbox(ttk.Combobox):
    def __init__(self, *args, sort=False, **kwargs):
        ttk.Combobox.__init__(self, *args, **kwargs)
        self.bind('<KeyRelease>', self.check)
        self.initial_values = self['values']
        self.sort=sort
        if self.sort==True:
            temp = list(self['values'])
            temp.sort()
            self.config(values=temp)
        self.insert(0, self['values'][0])
    
    def check(self, event):
        text = self.get()
        self.config(values=self.initial_values)
        temp = []
        for word in self['values']:
            if text.lower() in word.lower():
                temp.append(word)
        if self.sort == True:
            temp.sort()
        self.config(values=temp)

if __name__ == "__main__":
    countries = ['United States','Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antarctica','Antigua And Barbuda','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia And Herzegowina','Botswana','Bouvet Island','Brazil','Brunei Darussalam','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Central African Rep','Chad','Chile','China','Christmas Island','Cocos Islands','Colombia','Comoros','Congo','Cook Islands','Costa Rica','Cote D`ivoire','Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','French S. Territories','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guinea','Guinea-bissau','Guyana','Haiti','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Israel','Italy','Jamaica','Japan','Jordan','Kazakhstan','Kenya','Kiribati','Korea (North)','Korea (South)','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russian Federation','Rwanda','Saint Kitts And Nevis','Saint Lucia','St Vincent/Grenadines','Samoa','San Marino','Sao Tome','Saudi Arabia','Senegal','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','Solomon Islands','Somalia','South Africa','Spain','Sri Lanka','St. Helena','St.Pierre','Sudan','Suriname','Swaziland','Sweden','Switzerland','Syrian Arab Republic','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad And Tobago','Tunisia','Turkey','Turkmenistan','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','Uruguay','Uzbekistan','Vanuatu','Vatican City State','Venezuela','Viet Nam','Virgin Islands (British)','Virgin Islands (U.S.)','Western Sahara','Yemen','Yugoslavia','Zaire','Zambia','Zimbabwe']
    fruits = ['apple', 'pineapple', 'banana', 'kiwi', 'pamagranate', 'lemon', 'orange', 'papaya', 'tangerine', 'dragon fruit', 'cherry', 'sour cherry', 'watermelone', 'melone', 'strawberry', 'raspberry', 'sweet potato', 'tomato', 'cabbage']
    root = Tk()
    root.geometry('800x400+200+200')
    Label(root, text="List of All countries: ", font=(None, 24)).grid(row=1, column=1)
    Label(root, text="List of some fruits: ", font=(None, 24)).grid(row=2, column=1)
    Searchbox(root, values=countries, font=(None, 24)).grid(row=1, column=2)
    Searchbox(root, sort=True, values=fruits, font=(None, 24)).grid(row=2, column=2)
    Label(root, text="Good Luck.", font=(None, 24)).place(x=300, y=300, width=200, height=100)
    root.mainloop()