- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 161字
- 2021-08-27 19:44:05
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
推薦閱讀
- 新編Visual Basic程序設計上機實驗教程
- Instant Testing with CasperJS
- Objective-C Memory Management Essentials
- Software Defined Networking with OpenFlow
- 劍指Offer(專項突破版):數據結構與算法名企面試題精講
- Python深度學習
- JavaFX Essentials
- C#程序設計教程
- JSP開發案例教程
- 機器學習與R語言實戰
- Clojure for Machine Learning
- Orchestrating Docker
- ActionScript 3.0從入門到精通(視頻實戰版)
- Python一行流:像專家一樣寫代碼
- AVR單片機C語言應用100例