Jump to content

Recommended Posts

Posted

I'm making a keyboard to make a new name for a box that will be stored in my warehouse. Each added letter will be stored in a list, and then a string is made from all these letters/numbers/spaces..

I'm trying to get the pixel size (width) of that string each time something is added to see if it still fits on the screen, if not it will delete the last added again.

I have been trying to get the text_width working, but I don't understand what I'm doing wrong as I only get errors.

Information at https://pybricks.com/ev3-micropython/media.html#module-pybricks.media.ev3dev

ev3 = EV3Brick()
 
small_font = Font(size=6)       # 6 pixel height for text on screen
ev3.screen.set_font(small_font)   #Choose a preset font for writing next texts
ev3.screen.clear()              #Make the screen empty (all pixels white)
 
print(ev3.screen.text_width("lbg 13l"))
ev3.screen.draw_text(72, 15, "lbg 13l", text_color=Color.BLACK, background_color=Color.WHITE)    
 
AttributeError: 'Image' object has no attribute 'text_width'

I was expecting to have an amount of pixels to be shown as an integer in the Output box from Visual Studio Code. If I get that working I can use it in the real coding for the namegiving.

 

 

 

Posted
21 hours ago, David Lechner said:

 


width = small_font.text_width(text)

 

Thanks!

            for x in temp_name_list:
                temp_name += x
            if small_font.text_width(temp_name) > max_length_screenname:
                temp_name_list.pop()

Works perfect, now I can finish my HMI and start real testing soon.

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...