Skip to main content

A simple tool to create events to PySimpleGUI

Project description

Events For SimpleGui

Status of project: in progress...

This project has the intention to make easier, scalable and readable events on PySimpleGUI

Download

Download from PyPi

$pip install EventSimpleGUI

Demonstration

Creating an event function

Using the decorator event to run an event, you can pass the element key as an argument for decorator, when the event is called, function is going to be called two

from pysimpleevent import EventSimpleGUI
import PySimpleGUI as sg

loop = EventSimpleGUI()


@loop.event('_click')
def when_btn_was_clicked(*ags):
    print('Just a normal event')

layout = [[sg.B('Just a button', key='_click')]]
window = sg.Window('Just a Window.', layout)

if __name__ == '__main__':
    loop.run_window(window)

Events can be passed as an argument of run window like in the exemple

from pysimpleevent import EventSimpleGUI
import PySimpleGUI as sg

loop = EventSimpleGUI()



def when_btn_was_clicked(*args):
    event, _, _ = args
    if event == '_click':
        print('Just a normal event')

layout = [[sg.B('Just a button', key='_click')]]
window = sg.Window('Just a Window.', layout)

if __name__ == '__main__':
    loop.run_window(window, when_btn_was_clicked)

And can also pass an event using add_event

from pysimpleevent import EventSimpleGUI
import PySimpleGUI as sg

loop = EventSimpleGUI()



def when_btn_was_clicked(*args):
    event, _, _ = args
    if event == '_click':
        print('Just a normal event')

loop.add_event(when_btn_was_clicked)
layout = [[sg.B('Just a button', key='_click')]]
window = sg.Window('Just a Window.', layout)

if __name__ == '__main__':
    loop.run_window(window)

Events

You can use a sting or list of keys to trigger your events

from pysimpleevent import EventSimpleGUI
import PySimpleGUI as sg


loop = EventSimpleGUI()

keys = ['_click', '_click1']
@loop.event(keys)
def when_btn_was_clicked(*args):
    print('Just a normal event')


layout = [
    [sg.B(f'{"Just a button":54}', key='_click')],
    [sg.B(f'{"Just another button":50}', key='_click1')]
]
window = sg.Window('Just a Window.', layout, scaling=1.5)
if __name__ == '__main__':
    loop.run_window(window, window_log=True)

Change log 0.2.7

  • Tests are implemented 97% cov
  • Close event replaced to the end of loop

Change log 0.2.5

  • Now events can return values on Values dict

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EventSimpleGUI-0.2.9.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file EventSimpleGUI-0.2.9.tar.gz.

File metadata

  • Download URL: EventSimpleGUI-0.2.9.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for EventSimpleGUI-0.2.9.tar.gz
Algorithm Hash digest
SHA256 68e4201e28a47fc16fecb654514086160c534301b260990ea019d6adc508b663
MD5 ae6eb454a10ce8d5a31e89dc321417cb
BLAKE2b-256 c5b198753da6b7158c78ae57d09a4c926f7d5683b6bca628306d199031c13ed5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page