Giter VIP home page Giter VIP logo

Comments (19)

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

My use case is very simple and I want to know if PysimpleGui can accommodate the use of dynamically updating a button’s text and color based on a changing status. No input(clicking a button) etc is involved.

Yessir!

If you use the call sg.write_event_value then you can inject an event into your event loop and change the information there. It's the same call that you can use from a thread (the only call you can use from a thread).

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

Excellent, I will look up the documentation on that call. Also, do you offer a box element to basically do what I need without having to formally use a button element with all the disabled=T/F etc attributes for a status box?

from pysimplegui.

jason990420 avatar jason990420 commented on May 30, 2024

Not sure what the expectation, but

Example Code here for you

from time import sleep
from random import randint
import PySimpleGUI as sg

def capture():
    global running, temperature
    while running:
        temperature = (temperature + randint(-10, 10)) % 100
        window.write_event_value("Update", temperature)
        sleep(1)

settings = {
    "Normal": {"disabled":True,  "button_color":("white", "blue")},
    "Alarm" : {"disabled":False, "button_color":("white", "red" )},
}
temperature, state = 25, "Normal"
layout = [
    [sg.Push(), sg.Button("Alarm", font=("Courier New", 24, "bold"), **settings[state]), sg.Push()],
    [sg.Text("Temperature:", justification='center', expand_x=True, key="TEMPERATURE")],
    [sg.Text('', size=(50, 1), relief='sunken', font=('Courier', 11), text_color='yellow', background_color='black', key='TEXT')],
]
window = sg.Window("Demo", layout, enable_close_attempted_event=True, finalize=True)
running = True
window.perform_long_operation(capture, "Done")

while True:

    event, values = window.read()

    if event == sg.WINDOW_CLOSE_ATTEMPTED_EVENT:
        running = False
    elif event == "Update":
        temperature = values[event]
        window['TEXT'].update('█'*temperature)
        window['TEMPERATURE'].update(f"Temeperature:{temperature}")
        state = "Normal" if 15 <= temperature <= 35 else "Alarm"
        window['Alarm'].update(**settings[state])

    if event == "Done":
        break

window.close()

image

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

Most things are "clickable" so that you'll get an event. If you use an Image element to display an image and set enable_events=True, then you'll get an event when the image is clicked. Check the different elements for this capability.

I'm confident you'll be able to build something you'll like if you study the library for a short while. There are a lot of examples for you to see and run, and excellent documentation.

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

I can't understand a mass of code and text.... a picture I can make sense of though. A sketch would even work.

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

I don't see anything. Replying to GitHub issues doesn't post images, format your code, etc. I'm happy to try and help. Determining if a library can do what your project needs is a good sized portion of the work, as I'm sure you've encountered in your long history of programming. A sketch usually answers the basic capability question, but even then if the specific desired approach isn't doable, there are often other approaches that can be taken.

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

If you want to post a Visio diagram, export/save as a PNG/JPG, come to the GitHub issues on the web, drag and drop into a comment. Replying via email is not helpful.

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

Here is the diagram depicting the use case.
BGP Peer dashboard

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

You can change a PySimpleGUI window from any place in your code you want as long as it's the main thread. It cannot be another thread.

I don't see a problem with doing the kind of operation you're after. It's not a difficult operation to update an element.

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

Since you're talking about a dashboard of sorts, there's a dashboard mock-up in the eCookbook you can run and look at the code if that would help you see that you don't need to do anything in order to change things in the GUI. When the program starts you don't need to do anything to "start" it.

https://docs.pysimplegui.com/en/latest/cookbook/ecookbook/elements/graph/dashboard-mockup/

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

Got it thank you.. Greatly appreciate the patience. Thanks again..

You're welcome.... we're here to help... best of luck with your program! Come back when you're done and post a screenshot if you are able to.

from pysimplegui.

jsicuran avatar jsicuran commented on May 30, 2024

Thank you. I will look into the the link in the cookbook and check it out. I did look at the cookbooks old and the eCookbooks.
I just wanted to know if it was possible before going deeper into PySimpleGUI. I will definitely post a pic of the end result and again greatly appreciate the assistance.

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 30, 2024

again greatly appreciate the assistance.

Thank you image for the "thank you"! It's nice to know when we've helped. Have fun.... enjoy the ride!

from pysimplegui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.