Comments (10)
Not really thought about it, but no reason why not!
from guizero.
I am going to add ListBox
into the next release.
This is what Im thinking:
ListBox
will inherit fromTextWidget
- The interface will be very similar to
Combo
having a list ofoptions
aselected
and the ability to add an option and clear - tkinter doesnt provide a
command
for a Listbox so I will add an event to detect mouse clicks and use that to generate a command when the ListBox changes - scrollbars will be needed, Ill make this a option on the constructor, like a multiline TextBox
Any thoughts, greatly received.
from guizero.
Things to think about would be how the command parameter would deal with multi selection. Would it pass as argument one of the command function the selected items from the ListBox in a list?
To be honest I don't think you would need a command argument for the first crack at a ListBox. If the ListBox had a selected() function that returns a list of selected items, then you could use a PushButton with the ListBox as one of the list parameter, and inside that command function linked to the button use ListBox.selected().
from guizero.
@harlekuin thanks for the input.
Im not sure about the command yet either... but I think its important that there is an event that fires when the selection of a ListBox changes, it doesnt necessarily have to return anything though.
Re a selected()
function. I will implement a value
property (to be consistent with other guizero widgets) which either returns single value if the ListBox is a "single select" listbox or a tuple of values if the ListBox is "multi select" .
multiselect
will be a parameter passed in at construction, defaulted to False
.
e.g.
to create a single select list box:
lb = ListBox(app)
or a multiselect listbox:
lb = ListBox(app, multiselect=True)
from guizero.
Ok, so update..
In regards to ListBox API.
Ignoring all the stuff which ListBox will inherit from TextWidget (bg
, text_color
, font
, after
, etc, etc) it will have the following properties and methods.
__init__(self, master, items=None, selected=None, command=None, args = [], grid=None, align=None, visible=True, enabled=None, multiselect=False)
- master - container the widget is 'owned' by
- items - a list of string for items to add into the ListBox
- selected - item or items to select at init
- command - a function which will get called when the ListBox selection changes
- args - a list of arguments to pass to the command
- grid - grid position
- align - alignment in grid
- visible - if visible at init
- enabled = if enabled at init
- multiselect - if the ListBox should allow multiple items to be selected
value
- Sets or returns the items selected in a ListBoxNone
if 0 items are selected. If the ListBox is amultiselect
,value
is a tuple of items selected, if notvalue
is a single integer.insert(index, item)
- Insert a newitem
atindex
.append(item)
- Appends a newitem
to the end of the ListBox.remove(item)
- Removes anitem
from the ListBox.clear()
- Clears all the items from a ListBoxitems
- Returns a list of items in the ListBox
from guizero.
Another thought - a problem with having a command run on selection change is that it might not match the common use case for a multi-select listbox where the user selects several options before running a function on the "finalised" selections. In the pizza toppings case, the user would be picking x out of y possible toppings, and it doesn't make sense in this case (I think) to run the command for ('cheese'), then ('cheese', 'ham') then ('cheese', 'ham', 'pineapple'). Maybe this is just an example where a button with the finalised function would make more sense.
Also, would there be the listbox.value as the first argument as default of any command function?
What are your thoughts on making multiselect=True as the default? not a big thing but a single-select listbox is quite similar to a combobox in use cases so I can see multi-select being used more often.
will remove(item)
find the first instance of the item in the box? or will it remove multiples if they exist?
from guizero.
My thoughts for including a command
is to support knowing when the value within a ListBox has changed, not to return what the value is / was. I think this is the right approach as with a listbox its possible the change to the value could be that something has been deselected so there is no value.
Command will be optional so its a feature rather than a requirement.
My choice for multiselect = False is that it is consistent with tkinter and in-line with multiline in TextBox.
The append
, insert
, remove
methods will be consistent with a Python list, so yes remove
will remove the first instance of an item found.
from guizero.
I am thinking perhaps command
should return an optional parameter if the callback accepts it, similar to combo, buttongroup, etc. As @harlekuin said it could just return the value of value
.
from guizero.
This is in dev and will be in 0.5.1 - I think the internal code will need refactoring in the future, its was surprisingly difficult to add a scrollbar to the listbox and still have it work in a "guizero" way.
I think we can do better, perhaps as part of the layouts work for 0.6.0, but for the moment this is good and the API works well.
from guizero.
in 0.5.1 just released
from guizero.
Related Issues (20)
- Bug report - Documentation Fix HOT 3
- Bug report in documentation - Widgets - Window - Creating a Window object HOT 1
- Request to have SVG image support. HOT 1
- Slider 'end' starting parameters. HOT 4
- Mention App().tk.geometry() Functionality HOT 2
- guizero title font (not titlebox) HOT 12
- when_mouse_leaves does not seem to be detected correctly HOT 6
- Image resizing - cannot scale the image as PIL is not available HOT 4
- Gradually Increases Memory HOT 11
- Enter key not detected in key event HOT 4
- Widgets can be given a tab order
- Color control - TextBox Background and Pushbutton HOT 1
- Destroying a container could destroy the widgets contained inside it. HOT 3
- Guizero animation importing picture into a moving oval HOT 2
- Scrollable boxes (really a box inside a scrollable canvas)
- Create right-click context menu for copy-paste with app.add_tk_widget HOT 1
- MCP3008 HOT 4
- Pillow.Image.ANTIALIAS is deprecated and will be removed HOT 1
- #Recursive call dont work in Guizero_Auto_Update HOT 6
- TextBox command HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guizero.