[Python] Why is the the grid layout not centered on my window

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm making a game and trying to place a button at the center of the screen. However, using center_x and center_y does not correctly center the button. I attempted to use a GridLayout with 3 columns and placed the button in the 5th cell (out of 9), but the grid itself does not seem centered.

    I suspect that self.width and self.height might be the issue, but another part of my code (which draws a background grid) uses these values without any problems.

    Summary of my issue: Expected behavior: The grid and button should be centered on the screen. Actual behavior: The grid itself is not centered. Assumptions: self.width and self.height should be equal to the window size, and the window size does not change.

    #Code is in the pictures

    enter image description here enter image description here

    Things I've Tried

    Checked if self.width and self.height changed before start_screen() → They did not, the values remained correct. Tried using FloatLayout instead of GridLayout → The issue persisted.

    Continue reading...

Compartilhe esta Página