= How to create a list box (Phoenix) =
'''Keywords :''' List box.

<<TableOfContents>>

--------
= Introduction : =
{{{wx.Listbox}}} is a widget that consists of a scrolling box and a list of items.

User can select one or more items from that list

It depends on whether it is created as a single or multiple selection box.

Selected items are marked.

(info by '''ZetCode / Jan Bodnar''').
--------
= Demonstrating : =
__'''''Tested''' py3.x, wx4.x and Win10. ''__

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)

--------
== Sample one ==
{{attachment:img_sample_one.png}}

This example consists of four different widgets :

- wx.Listbox,

- wx.TextCtrl,

- wx.StaticText,

- wx.Button.

Widgets are organized with wx.BoxSizer.

wx.Listbox has a list of six different world times.

These abbreviations are explained in the wx.TextCtrl.

Current time is displayed in the wx.StaticText widget.

wx.Timer widget is used to update the time every 100 miliseconds.

{{{#!python
# sample_one.py

"""

Author : Jan Bodnar
Website : zetcode.com

"""

import wx
from time import *

# class MyFrame
# class MyApp

#---------------------------------------------------------------------------

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title,
                          wx.DefaultPosition, (430, 300))

        self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
        self.SetMinSize((430, 300))

        #------------

        zone_list = ['CET', 'GMT', 'MSK', 'EST', 'PST', 'EDT']

        self.full_list = {
            'CET': 'Central European Time',
            'GMT': 'Greenwich Mean Time',
            'MSK': 'Moscow Time',
            'EST': 'Eastern Standard Time',
            'PST': 'Pacific Standard Time',
            'EDT': 'Eastern Daylight Time'
        }

        self.time_diff = {
            'CET' : 1,
            'GMT' : 0,
            'MSK': 3,
            'EST': -5,
            'PST': -8,
            'EDT': -4
        }

        #------------

        self.diff = 0
        self.timer = wx.Timer(self, 1)
        self.timer.Start(100)

        #------------

        # wx.Font(pointSize, family, style, weight, underline, faceName)
        font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
        font.SetWeight(wx.BOLD)

        #------------

        panel = wx.Panel(self, -1)

        self.time_zones = wx.ListBox(panel, 26, wx.DefaultPosition, (180, 130), zone_list, wx.LB_SINGLE)
        self.time_zones.SetSelection(0)
        self.time_zones.SetFont(font)
        self.time_zones.SetForegroundColour('Black')
        self.time_zones.SetBackgroundColour('#cce8ff')

        self.text = wx.TextCtrl(panel, -1, 'Central European Time', size=(180, 130), style=wx.TE_MULTILINE)
        self.text.SetFont(font)
        self.text.SetForegroundColour('Black')
        self.text.SetBackgroundColour('#cce8ff')

        self.time = wx.StaticText(panel, -1, '', (-1, -1), (100, -1), wx.ALIGN_CENTER)
        self.time.SetFont(font)
        self.time.SetForegroundColour('#0078d7')

        btn = wx.Button(panel, wx.ID_CLOSE, '&Close')

        #------------

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        hbox3 = wx.BoxSizer(wx.HORIZONTAL)

        hbox1.Add(self.time_zones, 0, wx.TOP, 40)
        hbox1.Add(self.text, 1, wx.LEFT | wx.TOP, 40)
        hbox2.Add(self.time, 1, wx.ALIGN_CENTRE)
        hbox3.Add(btn, 0, wx.ALIGN_CENTRE)

        vbox.Add(hbox1, 0, wx.ALIGN_CENTRE)
        vbox.Add(hbox2, 1, wx.ALIGN_CENTRE)
        vbox.Add(hbox3, 1, wx.ALIGN_CENTRE)

        panel.SetSizer(vbox)

        #------------

        self.Bind(wx.EVT_BUTTON, self.OnClose, id=wx.ID_CLOSE)
        self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=26)
        self.Bind(wx.EVT_TIMER, self.OnTimer, id=1)

    #-----------------------------------------------------------------------

    def OnClose(self, event):
        self.Close()


    def OnSelect(self, event):
        index = event.GetSelection()
        time_zone = self.time_zones.GetString(index)
        self.diff = self.time_diff[time_zone]
        self.text.SetValue(self.full_list[time_zone])


    def OnTimer(self, event):
        ct = gmtime()
        print_time = (ct[0], ct[1], ct[2], ct[3]+self.diff, ct[4], ct[5], ct[6], ct[7], -1)
        self.time.SetLabel(strftime("%H:%M:%S", print_time))

#---------------------------------------------------------------------------

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'wx.ListBox')
        frame.Centre()
        frame.Show(True)

        return True

#---------------------------------------------------------------------------

app = MyApp(0)
app.MainLoop()
}}}
--------
= Download source =
[[attachment:source.zip]]

--------
= Additional Information =
'''Link :'''

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/

--------
= Thanks to =
Jan Bodnar (sample_one.py coding), the wxPython community...

--------
= About this page =
Date(d/m/y)     Person (bot)    Comments :

27/12/20 - Ecco (Created page for wxPython Phoenix).

--------
= Comments =
- blah, blah, blah....