官术网_书友最值得收藏!

How it works...

We create an empty Listbox object and add all the text items with the insert() method. The 0 index indicates that the items should be added at the beginning of the list. In the following code snippet, we unpacked the DAYS list, but individual items can be appended at the end with the END constant:

self.list.insert(tk.END, "New item") 

The current selection is retrieved using the curselection() method. It returns the indices of the selected items to transform them to the corresponding text items we called the get() method for each index in a comprehension list. Finally, the list is printed in the standard output for debugging purposes.

In our example, the selectmode option can be changed programmatically to explore the different behaviors, as follows:

  • SINGLE: Single choice
  • BROWSE: Single choice that can be moved with the up and down keys
  • MULTIPLE: Multiple choice
  • EXTENDED: Multiple choice with ranges that can be selected with the Shift and Ctrl keys
主站蜘蛛池模板: 同德县| 阿城市| 顺义区| 遂溪县| 依安县| 鄄城县| 苍山县| 阿拉善左旗| 抚顺市| 三明市| 武平县| 黑龙江省| 定州市| 朔州市| 辛集市| 剑川县| 彭阳县| 双柏县| 上饶市| 黔西| 揭西县| 新干县| 蓬安县| 泊头市| 黄梅县| 定陶县| 上林县| 黄大仙区| 辉县市| 台北县| 河南省| 高台县| 博野县| 沅陵县| 措美县| 汉沽区| 白沙| 湘潭市| 广宁县| 彭州市| 普洱|