Python Forum
Smoothen reset and write text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smoothen reset and write text
#1
Hi,

I am currently projecting the value as received from a sensor. Now the problem I saw was that on every value change, there is a flicker generated while the text changes (I'm guessing it is because I reset the turle writing the text before writing the new text).

Any suggestions on how I can reduce / remove this flicker / roughness during text change?

Thanks
Reply
#2
Please explain your environment.
What packages are you using?
Show code.
Reply
#3
I am working on a beagle bone black. The output is projected using a TI DLP LightCrafter 2000.
Message protocol in use is I2C.

Packages in use: I2C, TKinter, Canvas, TurtleScreen, RawTurtle

Code snippet:

# initialisation 
self.current_state = get_default_state()
self.current_state.draw_persisting() #draw stuff for this state which wont be changing until state change
while 1:
    check_for_state_change() #check if current state must be changed, if so change it and redraw persisting
    changing_turtle.reset() # different turtles for persistent and changing
    self.current_state.draw_changing() #this line here causes some text to be re-written every second
    #sleep for 1 second
self.current_state.draw_changing() is causing the main problem as every second it will call the write text function. The text changes as expected, but its isn't smooth. Something like a lag is experienced.
Reply
#4
unless you show that code, it's hard to say what the problem might be
Reply
#5
# initialisation 
self.current_state = get_default_state()
self.current_state.draw_persisting() #draw stuff for this state which wont be changing until state change
while 1:
    self.check_for_state_change() #check if current state must be changed, if so change it and redraw persisting
    self.current_state.draw_changing() #this line here causes some text to be re-written every second
    #sleep for 1 second
def draw_changing(self):
        self.changing_turtle.clear()# different turtles for persistent and changing objects
        self.changing_turtle.up()
        self.changing_turtle.sety(20)
        self.changing_turtle.color("yellow")

        self.changing_turtle.down()
        now = datetime.now()
        current_time = now.strftime("%H:%M:%S")
        self.changing_turtle.write(current_time, align="center", font=("Arial", 30, "bold"))
I can't edit my old comment for some reason, so I've re-written the first part (moved the clear into the function as it originally was).
Reply
#6
you can edit after a small number of posts (an-spam measure).
I found this on smooth scrolling: https://stackoverflow.com/a/53094796
Hope it's useful, I don't use turtle graphics myself.
Reply
#7
I looked at the recommended approach and didn't find it useful.
That said, you mentioned that you don't use TKinter. May I ask what you use? The project is still in its infancy and I should be able to recommend changing to another graphics library instead. I would prefer one which comes with Python or is under MIT license.
Reply
#8
I didn't say that I didn't use tkinter, I don't use turtle graphics.

My favourite GUI is wxpython.

Others use Qt5 and/or Kivy
Kivy I understand is good if your code needs to scale to phones.

Qt5 is good, has a community edition, but I prefer wxpython because it's open source, and looks to stay that way.

Be aware the version of wxpython I use is Phoenix. pip install wxpython
If you decide to go this route, be sure to download the excellent demo.

I have a small example application here: https://python-forum.io/Thread-Perfectly...t=wxpython

you can see some the widgets available here: https://docs.wxpython.org/gallery.html
and docs here: https://docs.wxpython.org/index.html
Reply
#9
Thanks @Larz60+,

Your answer got me thinking of how turtle graphics is not the same as Tkinter (I'm very new to python). Anyway, I ended up removing the usage of turtle graphics in favour of using a tkinter label and changing it's text instead.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020