Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add 'events' to widgets

See original GitHub issue

There are a couple of open PR’s relating to adding events to widgets. #14 and #118 .

Its clearly a good idea, so I have opened this issue to keep track.

A couple of initial points / questions come to mine

  1. The implementation of this should be via a mixin, its a shared function of many widgets

  2. There is a choice re interface, functions or properties.

tk currently uses functions like on_mouse_click to set a command, this is familiar to tk users.

other “zero” libraries have moved to using properties to set a command, e.g. gpiozero

def my_func():
button = Button(17)
button.when_pressed = my_func

If implemented as properties (which I think is a good idea) should they be when_mouse_clicked, when_key_pressed, when_mouse_moved - its a bit more verbose, but it is simple to understand.

This also lends its self to implementing other events such as when_pressed for a PushButton or when_changed for a TextBox.

  1. The tk event callbacks will return Event objects - is this the right thing to do for guizero?

One of the problems is that the Event object is a tk object not a guizero object, so (as an example) it refers to the tk widget not the guizero widget.

I think the right approach is to create an Event structure for guizero which returns guizero widgets but could also be extended to include other useful values in the future e.g. “imagine a when_changed event on a Slider” would return the Event structure but also the value the Slider changed too.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

MrAHolmescommented, Aug 11, 2019

I am trying to code a combo box that when changed alters the colour of another text box. The combo box widget really needs a when_changed event. The existing events only track over the un-expanded COMBO box. This is messy as you have to position your mouse OVER the original combo box for mouse events to register AFTER you have actually made a change.

from guizero import App, Combo, TextBox,Text

lst_Colours = ['Gold',

app = App(title='Combo Box Event Issue',width=500,layout = 'grid')

lbl_promptColour = Text(app,text="Colour",grid=[1,0],width=15)
cbo_Colours = Combo(app,options=lst_Colours,selected=lst_Colours[0],grid=[1,1],width=15)
txt_ColourSwatch = Text(app,text="Colour \nSwatch",grid=[1,2],

def updateColourSwatch(): = cbo_Colours.value
    if cbo_Colours.value == "Black":
        txt_ColourSwatch.text_color = "White"
        txt_ColourSwatch.text_color = "Black"

cbo_Colours.when_left_button_released = updateColourSwatch
cbo_Colours.when_mouse_leaves = updateColourSwatch


edited to use code block

martinohanloncommented, Aug 11, 2019

Just used the standard command on the Combo box. You don’t need to use all the custom events.

cbo_Colours = Combo(app,options=lst_Colours,selected=lst_Colours[0],grid=[1,1],width=15,command=updateColourSwatch)

^ I haven’t tested this code, but that is what the Combo command does.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wordpress Event Widgets - Events Manager
Add wordpress event widgets to your blog with easy to use calendar, event list and location list widgets.
Read more >
How To Setup an Upcoming Events Widget in WordPress
Showing upcoming events in widgets​​ To add upcoming events to your sidebar, go to Appearance > Widgets. This will create a standard version...
Read more >
Events List Widget Settings - Knowledgebase
We'll show you how to configure the Event List Widget in this article. From there, you can customize the widget using a template...
Read more >
Adding event widgets to Overview page - Jive Software
Adding event widgets to Overview page · Click the drop-down arrow in the upper right corner of the widget and then click Edit...
Read more >
Creating A WordPress Events Widget On Your Website
Here are the steps that you need to take to add a Featured Event Widget to your website: · Go to WP admin...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found