0

I want to make my red text slowly turn to green (and later to blue). Of course I was traying to make it by myself. Here's the code where I was traying for start turn slowly color from black to red:

from guizero import App, Text
from time import sleep

done = 0
re = 0
ge = 0
be = 0

app = App("My title")
a  = Text(app, text="Hello World", color = "black")

while done == 0:
    a.text_color = (re, ge, be)
    re = re + 1
    if re == 256:
        done = 1
    sleep(0.1)

app.display()

Then when I'm turning on the code I see no error and app, IS on the screen, but it can't show any text and it's crushing (after some time I see "(not responding)" on the top of the app... and that's it!). I'm always see no error.

If it can help I'm working on mu.

I was traying:

  • diffriend way to make code delaying
  • put while command in the def loop
  • adding glabal command
  • combining these ideas

I can't fix it! Can someone help?

Please!

There is more data. By your commants I did new code where I started to do it fully (to first turn from red to green, later to blue and to again red) (there's again the same not responding problem):

from guizero import App, Text,PushButton
from time import sleep

re = 255
ge = 0
be = 0

don = 0
work = 1

def strt():
    global don, re, ge, be, work
    start.hide()
    seco.show()
    for x in range(2):
        don = 0
        while don == 0:
            if work == 1:
                if not re == 0:
                    re = re - 1
                    ge = ge + 1
                else:
                    work = 2
            elif work == 2:
                if not ge == 0:
                    ge = ge - 1
                    be = be + 1
                else:
                    work = 3
            elif work == 3:
                if not be == 0:
                    be = be - 1
                    re = re + 1
                else:
                    work = 1
                    don = 1
            seco.text_color = (re, ge, be)
            sleep(0.1)

app = App("Top Secret (yet)")
app.bg = "black"
fill = Text(app, "", 200)
start = PushButton(app, strt, text="Start!")
start.bg = "blue"
seco = Text(app, "nothing", 50, color = (re,ge,be), font = "Algerian")
seco.hide()

app.display()
Gutek
  • 11
  • 3
  • 1
    Notice that your app will now show until `app.display()` is executed. The loop before this causes the "not responding" error. I recommend that you learn about event driven programming in `guizero` to find a solution. You will need to find an event that will call a function ever `0.1` seconds while the window is displayed rather than trying to do it before the window displays. – Code-Apprentice Mar 25 '23 at 19:54
  • 1
    I have never used that library, but you dont run app.display() until the end of your program. Shouldnt that be in some kind of loop? – ph140 Mar 25 '23 at 19:54
  • I recommend solving a slight variation of what you are trying to do first: Add a button to your window. When the user clicks the button, change the text color from black to red. This will get you started learning about events and how to use them in your own program – Code-Apprentice Mar 25 '23 at 19:55
  • 1
    From there, check out [the documentation](https://lawsie.github.io/guizero/blocking/). This shows a similar example that changes the text instead of the color. You should be able to adapt this to your case. – Code-Apprentice Mar 25 '23 at 19:58
  • I'll check is it working. – Gutek Mar 26 '23 at 07:53
  • Oh no! It still don't work! – Gutek Mar 26 '23 at 12:10

0 Answers0