##########################################################################################
# Create a Tkinter screen with a label, a listbox and a button
# The listbox has a vertical scroll bar
##########################################################################################
from tkinter import *			            #import entire tkinter framework
from tkinter import messagebox              #import popup dialogs 

def submitEvent( ):                                         #method is called upon submit
    selected_idx = langListbox.curselection()               #get indexes of all selected in Listbox
    selected_val = ''    
    for i in selected_idx :                                         #loop thru the list
        selected_val += langListbox.get(i) +' '                     #get value selected in Listbox 
    messagebox.showinfo('Thanks', F"You entered: {selected_val}")   #display a popup dialog
    
#### Create the window components ###########################################################

win = Tk( )					                    #call Tk( ) constructor to create a root window
win.title("Tkinter Window with Listbox")	    #set a window title
win.geometry("350x180")                         #window size

frame1 = Frame( win, bg='cyan', bd=20, highlightthickness=2, highlightbackground="blue")

langs  = ('Java','Python','JavaScript','C','C++','C#','Go','PHP','Swift','SQL') 

langInput = StringVar(value=langs)              #the same, + provide the values of the Listbox

langLabel     = Label(frame1, text="Your favorite languages", bg="cyan")

langFrame     = Frame(frame1)
langListbox   = Listbox(langFrame, width=22, height=4,  listvariable=langInput, selectmode='extended') 
langScrollbar = Scrollbar(langFrame, orient="vertical", command=langListbox.yview)
langListbox.config(yscrollcommand=langScrollbar.set)
langListbox.pack(  side="left")
langScrollbar.pack(side="right", fill="y")

submitButton = Button(frame1, width=9, text="Submit", cursor='hand2', command=submitEvent)  #call submitEvent upon submit

#### Place components in window ###########################################################

langLabel.grid(   row=0, column=0, pady=6, padx=5, sticky=NE)
langFrame.grid(   row=0, column=1, pady=6, padx=5, columnspan=2)
submitButton.grid(row=1, column=0, padx=5, pady=8, sticky=E)

frame1.pack()                                                       #make the frame visible
win.mainloop()                                                      #make the window visible