[Python] How can I make both row and col coordinates to be the size of the window?

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a grid system for my tkinter window. I do not know how to do this correctly.

    def __init__(self,win,blocksx,blocksy,bg="#232627"):
    self.screenwidth = win.winfo_screenwidth()
    self.screenheight = win.winfo_screenheight()
    self.canvas = tk.Canvas(win,width=self.screenwidth,height=self.screenheight,background=bg)
    self.canvas.pack()
    self.background = bg
    self.parent = win
    self.winwidth = win.winfo_width()
    self.winheight = win.winfo_height()
    self.width = self.canvas.winfo_width()
    self.height = self.canvas.winfo_height()
    self.blockx = blocksx
    self.blocky = blocksy
    def coordinate(self,row,col):
    """
    Gets the coordinates
    of a certain block.
    """
    print(row*(self.width/self.blockx),"",col*(self.height/self.blocky))
    row -= 1
    col -= 1
    if row > self.blockx or col > self.blocky or row < 0 or col < 0:
    "raise positionError"


    The coordinate function should split the window into blockx columns and blocky rows. It does not, what is the correct equation? 1,1 would be equal to 0,0 in tkinter coordinates.

    Continue reading...

Compartilhe esta Página