#Need help pygame_gui functions is a little confusing

214 messages · Page 1 of 1 (latest)

latent streamBOT
#

@granite echo

devlop_gaming Uploaded Some Code

I'm getting an error.

relative_rect.height = -1 if wrap_to_height else relative_rect.height
                                                 ^^^^^^^^^^^^^^^^^^^^

AttributeError: 'tuple' object has no attribute 'height'

what does this mean and how do the relative_rect param work?

modules being used here is pygame and pygame_gui

Uploaded these files to a Gist
frank nest
#

what line gives you the error?

granite echo
#

45

#

ProjNameTextBox variable

frank nest
#

that line doesn't have relative_rect.height

#
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'height'``` where is this?
granite echo
#

that's the relative_rect paramater i think

frank nest
#

Uh...can you share the code where you wrote this line?

granite echo
#

like in a code block or the whole script?

#
ProjNameTextBox = pygame_gui.elements.UITextEntryBox((0,0,100,90),"New Project",manager,screen,visible=True)
frank nest
#

Wait, didn't you write relative_rect.height = ...?

#

who wrote that line??

granite echo
#

i think that error message is reffering to the very first paramater

#

which confuses me tho. Isn't relative_rect the same as pygame.Rect?

dark yacht
#

Is that .... character development?

granite echo
#

what is?

dark yacht
#

You reading docs

frank nest
#

Maybe it's a bug in the code that they wrote...

#

but instead of using a tuple, try using a pygame.Rect

granite echo
#

i'm thinking it's either similar to pygame.Rect or maybe it takes a rect???

#

now i'm getting another error and i don't get this one either

#
raise ValueError("container parameter must be of type "
ValueError: container parameter must be of type IContainerLikeInterface.
frank nest
#

What is it and what did you write?

granite echo
#
ProjNameTextBoxRect = pygame.Rect(0,0,100,90)
ProjNameTextBox = pygame_gui.elements.UITextEntryBox(ProjNameTextBoxRect,"New Project",manager,screen,visible=True)
#

this

granite echo
frank nest
#

What is it?

granite echo
#

pygame_gui.core.IContainerLikeInterface

frank nest
#

Pretty sure you are not supposed to use it

granite echo
#

uhm ik but idk how

frank nest
#

not**

granite echo
#

?

#

what

frank nest
#

you are not supposed to use it

granite echo
#

then what am i supposed to use

frank nest
#

I think you can leave it out

#

because I don't see anything in your code that implements that interface

granite echo
#

how do i draw it onto the screen?

#

i cannont find anything on how to draw it i don't even know if it's being drawn

#

Know what I'm just gonna create my own function. Might be easier that way. If anyone figure out how to use pygame_gui then lemme know.

frank nest
#

I fixed it @granite echo

granite echo
#

rlly?

frank nest
#

Not sure why you had this line near the bottom ```py

    manager = pygame_gui.UIManager((screen.get_width(),screen.get_height()))```
granite echo
#

can you send the fixed script

frank nest
#

Just remove that line

granite echo
#

i deleted everything already

frank nest
granite echo
#

what about it?

frank nest
#

Your code is still there

granite echo
#

the fixed version?

frank nest
#

no...

granite echo
#

i didnt mean i deleted the whole script

#

i meant i deleted the parts dealing with pygame_gui

frank nest
#

Just copy paste the lines that are missing facepalm

#

There's like 4 lines

granite echo
#

you didnt tell me which parts that needed to be fixed

frank nest
#

I did...

frank nest
granite echo
#

i'll do it in a minute i already have my ps5 on

dark yacht
granite echo
#

?

#

what

granite echo
#

got another problem

dark yacht
#

@frank nest

frank nest
dark yacht
#

understandable

granite echo
#

bruh dont blame me i never used pygame_gui before

frank nest
#

At least ask your question if you want help

dark yacht
#

I always remembered you saying that making the game was easy as hell for you

granite echo
#

it's not a game

dark yacht
#

pygame is not for the game?

granite echo
#

if you truley read the code you would notice most of my variable names is related to an engine

granite echo
dark yacht
#

Well you took like 900 lines of messages to write 18 lines of code so....

#

Yeah

granite echo
#

.

#

uhm i was doing something while tryna type which is why i kept pausing

#

anywho the text box isn't being sized correctly

#

it always stay at the same size no matter what i change it to

frank nest
granite echo
#

your tryna be funny

dark yacht
granite echo
#

whatever

dark yacht
granite echo
#

still not funny

granite echo
dark yacht
#

The one from the very beginning of this thread?

granite echo
#

yes

#

well i did make a change and that's the line you told me to remove

#

so like what's the issue?

frank nest
#

Did you fix it? @granite echo

granite echo
#

i just decided to make my own function

import pygame

def TextBox(Text,surface,antialias,font_size,font_color,x,y):
    font = pygame.font.Font("Engine/Fonts/Swansea-q3pd.ttf",font_size)
    font_rendered = font.render(Text,antialias,(font_color))
    surface.blit(font_rendered,(x,y))
#

works so far just gotta make it stay inside the window and at the interaction for the text box and the background color

granite echo
#

the text isn't centered like i want it to

#
gui.TextBox("New Project",screen,False,35,(0,0,0),(255,255,255),screen.get_width()/2,screen.get_height()/2)
frank nest
#

Subtract the text's height and width

granite echo
frank nest
#

No

#

From x and y position of the text

granite echo
#

In the main script or gui script?

#

Ik alot of questions but I just thought how would that work from the main script and the text is being drawn from the TextBox function

frank nest
#

Uh...I can't tell without looking at the code

granite echo
#

You have it wym

granite echo
frank nest
#

In the Gui file

granite echo
#

That is the gui file

frank nest
#

Actually, subtract half of the text's height and width from the x and y position

frank nest
granite echo
frank nest
#

Sure...if that's what you want

granite echo
#

Need*

frank nest
#

Idk how you want to render the font. Like are there some instances where you don't want to center the text? If so, add a parameter that allows the user to set it

granite echo
#

Actually this isn't exactly for user usage. .

frank nest
#

Do whatever you want 🤷‍♂️

topaz salmon
#

You should put your game on GitHub!

#

Then we can browse the code when you need help

granite echo
granite echo
topaz salmon
#

Why can’t the block based coding utilize your methods under the hood?

granite echo
#

Wdym

topaz salmon
#

the block based coding (i assume you mean something like scratch) needs to call your code to do things, like rendering a font

granite echo
#

Which is gonna be placed inside the project

topaz salmon
#

nice!

granite echo
#

All the data on block positions,value, and which script their in is all gonna be stored on the project

#

Haven't set those up yet bc first I had to finish up on the project page

granite echo
#

how do i use pygame event from a second file with the initiated module

#
import pygame

Text = ""

def TextBox(surface,antialias,font_size,font_color,bg_color,x,y):
    InputEnabled = True
    
    font = pygame.font.Font("Engine/Fonts/Swansea-q3pd.ttf",font_size)
    font_rendered = font.render(Text,antialias,(font_color),(bg_color))
    surface.blit(font_rendered,(x,y)).fit(surface.get_rect())

while True:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            Text += event.unicode
frank nest
#

Why do you want to do that?

granite echo
#

the answer staring you in the face

#

i'm making a text box and this is only part of what i came up with

frank nest
#

What???

granite echo
#

what

frank nest
#

You didn't answer my question

granite echo
#

i did wym

granite echo
#

do i need to hightlight it

frank nest
#

How does it answer a "why" question???

#

You just told me that this is what you wrote but why???

granite echo
#

i couldn't figure out pygame_gui so i decided to make my own function

#

literally said i was making my own function yesterday

frank nest
#

Can't you just pass in the event as a parameter???

granite echo
#

wdym

dark yacht
frank nest
#

Yeah I have no clue what you are trying to do. You need to explain why you need to use pygame event from a second file or what exactly you are trying to accomplish with it.

#

Also, stop that attitude of yours or I will close this post

frank nest
#

And you are trying to display the text that the user types in the TextBox???

granite echo
#

basically yea

frank nest
#

That's all you needed to tell me

granite echo
#

uhm i did?

#

so is there a way to do this in multiple scripts?

frank nest
frank nest
#

And where does it say, "I want to display the text to the user"? You could be doing anything with a text box

#

I am not here to read your mind.

granite echo
#

Who said you were and what else would text boxes be used for?

frank nest
#

You could be at any stage of making a TextBox.

granite echo
#

if i sent you the code which i did you can easily tell where i stopped at

frank nest
#

I am not going to guess what your code is trying to do because it's rubbish. It's easier if you just tell me what you are trying to accomplish which you have repeatedly failed to do.

granite echo
#

You don't need to guess you already know what the purpose of a text box is. It functions the same as it does in every engine and games in existence and i tried to explain.

frank nest
#

Anyways, I am not going to waste my time by arguing with you anymore. Good luck getting help with that attitude.

native perch
#

Being argumentative is an odd way of getting help... If someone is voluntarily helping you just be nice and answer their questions even if you don't understand why they're asking them

granite echo
native perch
#

Well, I'll end it, sooooooooo

granite echo
native perch
granite echo
# native perch How come

So I made an event script but I still nerd the main script to be able to access the event script functions

#

And I don't really see how that's gonna work at all

granite echo
topaz salmon
#

object oriented programming

#

If write an object you can store your event and whatever else you need in it and pass it around as a parameter

#

And then call the functions of the object or use any instance variables

granite echo
#

you could show an example of how to do it instead of just telling me

topaz salmon
#

It makes me not want to help you

granite echo
frank nest
#

do you not know OOP?

granite echo
#

i do

frank nest
#

So...what's the problem? What bapp explained is pretty basic...

granite echo
#

may not have payed much attention to the second part

frank nest
#

This is what happens when you use too much chat gippitty:

#

Can't write code on your own and rely on other people to write it for you

#

😂

granite echo
#

sometimes i really don't pay attention to what i'm doing now look at you don't know shit

frank nest
#

what

granite echo
#

wdym what

frank nest
#

Are you saying i don't know shit?

granite echo
#

about me or what i could be using to help write code yes

frank nest
#

It very much is whether you want to believe it or not

#

You literally put zero effort into what we tell you to do. We gave you resources, you didn't bother opening them. We told you how to fix your problem, you didn't bother to copy paste a few lines to make it work. We told you how to fix your problem again, you got sassy instead of asking nicely. Do you come here to ask for help or to show off that attitude?

granite echo
#

Firstly i do put in the effort most the time. Second i do open your resources sometimes i may not have the time to go through the whole thing. I ain't gonna have time after today and tomorrow. Also you did tell me how to fix the problem but you didn't show me so what am i supposed to do just guess? For the last question i came for help because what ever i find on yt or the internet i may be confused about or i don't fully understand or there may be information i'm looking for that i can't find.

frank nest
#

We are not going to hold your hand while you code, especially not with the attitude that you carry around. You clearly don't appreciate the help that others offer you but make snarky comments. How do you expect others to help you after that or write code for you?

granite echo
#

What snarky comments and what attitude?

frank nest
#

Oh so you are not even self-aware? Makes sense

granite echo
#

i almost called you something

frank nest
#

@granite echo

#

20 images in total

granite echo
#

you don't even understand why i said what i said in half of these 😒

frank nest
#

I do.

#

It' better to acknowledge that you were wrong than keep on arguing like a child...

granite echo
#

First of all no you don't and second wouldn't that make you a child yourself since your technically engaged in this conversation

frank nest
#

Except I am not wrong and you are...

native perch
#

!kick @granite echo I've stopped helping you because it always feels like an argument. Good luck with your project

latent streamBOT
#

devlop_gaming has been kicked