Commit 7c7ff01d authored by Guido van Rossum's avatar Guido van Rossum

- White background.

- Display "(None)" (or text of your choosing) when empty.
- Don't set the focus.
parent a8ed570c
from Tkinter import * from Tkinter import *
class ScrolledList: class ScrolledList:
default = "(None)"
def __init__(self, master, **options): def __init__(self, master, **options):
# Create top frame, with scrollbar and listbox # Create top frame, with scrollbar and listbox
...@@ -9,7 +11,8 @@ class ScrolledList: ...@@ -9,7 +11,8 @@ class ScrolledList:
self.frame.pack(fill="both", expand=1) self.frame.pack(fill="both", expand=1)
self.vbar = vbar = Scrollbar(frame, name="vbar") self.vbar = vbar = Scrollbar(frame, name="vbar")
self.vbar.pack(side="right", fill="y") self.vbar.pack(side="right", fill="y")
self.listbox = listbox = Listbox(frame, exportselection=0) self.listbox = listbox = Listbox(frame, exportselection=0,
background="white")
if options: if options:
listbox.configure(options) listbox.configure(options)
listbox.pack(expand=1, fill="both") listbox.pack(expand=1, fill="both")
...@@ -22,16 +25,21 @@ class ScrolledList: ...@@ -22,16 +25,21 @@ class ScrolledList:
listbox.bind("<ButtonPress-3>", self.popup_event) listbox.bind("<ButtonPress-3>", self.popup_event)
listbox.bind("<Key-Up>", self.up_event) listbox.bind("<Key-Up>", self.up_event)
listbox.bind("<Key-Down>", self.down_event) listbox.bind("<Key-Down>", self.down_event)
# Set the focus # Mark as empty
listbox.focus_set() self.clear()
def close(self): def close(self):
self.frame.destroy() self.frame.destroy()
def clear(self): def clear(self):
self.listbox.delete(0, "end") self.listbox.delete(0, "end")
self.empty = 1
self.listbox.insert("end", self.default)
def append(self, item): def append(self, item):
if self.empty:
self.listbox.delete(0, "end")
self.empty = 0
self.listbox.insert("end", str(item)) self.listbox.insert("end", str(item))
def get(self, index): def get(self, index):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment