if your backspace doesn't work try adding " clear_rect = pygame.Rect(left position, top position, width, height) " by your input_rect declaration and " pygame.draw.rect(screen, white, clear_rect) " beneath your "pygame.draw.rect(screen, color, input_rect, 2)"
how can i do it in the way that after writing the text in pygame and pressing enter the input is saved and checked by the program to see if its correct or not
Here to add a little bit of extra info If for some reason your new text is overlapping with your previous text Add a line Screen.fill((0,0,0)) After user_text=user_text[:-1]
When I press backspace it just moves back a letter instead of deleting the last one. So when I clicks another key it writes over other text that hasn’t been deleted. Help
Not entirely sure this works nor have I tried it myself yet and I'm probably late anyway but could you print the text to the screen then do the coordinates that the text renders to -1 on the y axis
amazing tutorial, but is there a way of typing in different places and switching between them? if its what u meant by saying "multiple strings are not supported" then sry
My backspace is not working. If I type something and I press backspace, the characters do not go away, and if i type something again, it overlaps the existing characters
I don't know if you still need it, but the problem is that screen.blit(user_text etc ) keeps writing the text above the previous one, so you don't notice that when you use event.unicode, since the program keeps writing the same string you can roughly cover the previous one by drawing a smaller and fully coloured rectangle inside the one that you already have
I'm not new with python and pygame but it didn't came to my mind to use "max" for the width of rect. Why I'm always forgetting "max" and "min" function?
How I did this before watching this (I still have it like this) is I wrote lines of code to get text input for every single letter, numbers and symbols because I didn't realize event.unicode was a function. And it is a success so I don't want to waste it now -_-
@@TutorialTube448 any text. for example I copy "Hello World", I past it and it shows a rectangle. (i am pasting this on the window. I would imagine this should work as if you wrote the entire text you are trying to paste as if you typed it word by word)
If you want to make this while the game is running, you can make a rectangle at the bottom asking for the name and stop all inputs of moving the player and then do the steps in the video. I guess this should work anyway
You can define a new loop at the end of your program and add this code inside, also add this: if event.key == pygame.K_RETURN: global i i = user_text main() # Your loop's name might be different Then blit the text as the variable i at the start of your main (or other) loop.
I am a learner and i just started coding, i am getting an error that (name += event.unicode TypeError: unsupported operand type(s) for +=: 'pygame.Surface' and 'str')
Hey I'm having a problem with the colors: "color_active = pygame.color('lightskyblue3') TypeError: 'module' object is not callable" Can anyone help me?
Hi, try this: color_active = pygame.Color('lightskyblue3') It looks like there is a syntax error. The letter "c" in "pygame.color" has to be uppercase. hope this helps
@@ClearCode when I did that, it said: line 16, in text_surface = base_font.pygame.render(user_text,True,(255,255,255)) AttributeError: 'pygame.font.Font' object has no attribute 'pygame'
you don't have to believe but pygame is a great module in making sliders, however tkinter (module that you don't need to download in anything because it is part of python) can do a great job in making a slider] Widgets are various controls, such as buttons, labels, scrollbars, radio buttons, and text boxes used in a GUI application. They are also little components or controls of Graphical User Interface (GUI). Pady Puts some space between the button widgets and the borders of the frame and the borders of the root window Pack Is a geometry manager that just basically stacks widgets on top of each other. TKINTER CODE FOR MAKING SLIDERS slider_frame = tk.Frame(root, borderwidth=5, relief=tk.SUNKEN) # -- slider_frame.pack(pady=10) slider = tk.Scale(slider_frame, from_=0.00,# starting point of the range for sliding from.(minimum) to=1.0, and this is the max in the range orient=tk.VERTICAL, for the way it is going to be seen as length=400, -- how long the widget is tickinterval = 0.1, resolution = 0.01, slider.pack()
I want to put a limit to the characters, does anyone know how to do that?? Also I really need help with this: if input_rect.collidepoint(event.pos): It is giving me this error: AttributeError: 'tuple' object has no attribute 'collidepoint'
for the character limit, go with something like if len(user_string) < char_limit: then add the user string and for the error below, it seems that your input_rect variable does not have a rectangle but a tuple, check what you put inside of that.
@@ClearCode Thanks so much, I figured it out. I put active = False when the rect is more than 250 pixels wide so you can't expand the rect more and you cant type, also I figured out the rect tuple problem, I put input_rect = (WIDTH/2 - 130 , 500, 140, 32) instead of input_rect = pygame.Rect(WIDTH/2 - 130 , 500, 140, 32)
@@Ashersminicartoons glad it worked out for you :) Although, do be aware that different characters usually have different widths, so your approach wouldn't limit the character count consistently, just be aware of that.
You can use the assert statement as try: assert len(user_text) < (limit) : pass except AssertionError: print("Limit exceeded") This is the other way to add limitations.