#πŸ”’ Positioning an image in a window

49 messages Β· Page 1 of 1 (latest)

maiden anchor
#

Hi, im making a game where i have to position a lot of pictures in a window that have the same distance between them and so it looks straight, but i dont know the best way of doing it.
this is the code im currently using, which is annoying to use:

firstpos = [scw_x + case_image_width//3, scw_y + case_image_height//2]
        secondpos = [firstpos[0] + case_image_width*1.5, firstpos[1]]
        thirdpos = [secondpos[0] + case_image_width*1.5, firstpos[1]]
        fourthpos = [thirdpos[0] + case_image_width*1.5, firstpos[1]]
        fithpos = [fourthpos[0] + case_image_width*1.5, firstpos[1]]
        sixthpos = [firstpos[0], firstpos[1] + case_image_height + case_image_height//2]
        seventhpos = [secondpos[0], sixthpos[1]]
        eigthpos = [thirdpos[0], sixthpos[1]]
        ninthpos = [fourthpos[0], sixthpos[1]]
        tenthpos = [fithpos[0], sixthpos[1]]

but the items on the screen gets misplaced for some reason

keen rapidsBOT
#

@maiden anchor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

maiden anchor
#

see how things aren't alligned^^

maiden anchor
untold lotus
#

What GUI library are you even using?

maiden anchor
#

none

#

im making it myself xD

untold lotus
#

!paste

keen rapidsBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

maiden anchor
#

i didn't think of using a GUI library that would prob be smart

untold lotus
#

Then you need to provide more context.

maiden anchor
#

do you reccomend one?

untold lotus
#

!pip pygame-ce

keen rapidsBOT
untold lotus
#

!pip pyside6

keen rapidsBOT
#

Python bindings for the Qt cross-platform application and UI framework

Released on <t:1712660635:D>.

untold lotus
#

pygame-ce has some nice abstractions for writing games

maiden anchor
maiden anchor
untold lotus
#

GUI libraries have things like geometry managers that handle all the specific positioning for you (although you can override that and put things where you want if you want).

maiden anchor
#

okok thank you

untold lotus
#

You're welcome.

maiden anchor
#

is pygame-ce just pygame?

#

cus im using pygame right now

untold lotus
#

There was some internal drama, the pygame maintainer didn't maintain pygame for awhile and didn't accept patches, all the developers left to fork pygame-ce

#

!pip pygame

keen rapidsBOT
untold lotus
#

note the last release dates

maiden anchor
#

ohhh ok

#

but is there built-in liberaries for GUI in pygame?

#

like how do i use pygame to build a GUI with "geometry managers that handle all the specific positioning for you"

untold lotus
#

I don't think so.

maiden anchor
#

sooo, how do you reccomend i build this "select cases" window?

#

for each item to be positioned straight and alligned

tidal oar
#

Or am I blind

maiden anchor
#

no its only the text

#

but i found out how to place the images with good alignement

#

but i can't figure out why the "ADD" text gets so off

#

this is how the cost price is placed:

textRect.center = (pos[0] + case_image_width//2, pos[1] + case_image_height*1.2)
#

and i just copy pasted that for the "ADD" text, but of course changed the Y value

#

so i don't get why the ADD text is so off and the cost text is not

tidal oar
#

Ohhh

#

Hmmm those images are rects right?

#

Why not just position the text by the rect position like text_rect.midtop=(image_rect.midbottom + space)

keen rapidsBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.