How to get grid information from pressed Button in tkinter?

前端 未结 3 2009
深忆病人
深忆病人 2021-01-14 13:13

I need to create table of buttons using Tkinter in Python 2.7, which has n rows and n columns, and has no button in bottom right corner.

P

3条回答
  •  [愿得一人]
    2021-01-14 13:59

    This is the way I tried to do this and problem is that I still don't know how to get row and column of pressed button...

    from Tkinter import *
    
    #Input:
    n = int(raw_input("Input whole positive number: "))
    L = range(1,n+1)
    k = n
    m = n
    #Try putting values for k and m which are less then n and you will see what   i need to get
    
    #Moving:
    def Move():
        #This i cant fill
        return k,m
    
    #Program:
    root = Tk()
    for i in L:
        for j in L:
            frame = Frame(root)
            frame.grid(row = i,column = j)
            if i == int(k) and j == int(m):
                pass
            else:
                button = Button(frame, command = lambda: Move())
                button.pack()
    
    root.mainloop()
    

    So by changing k and m values gap is created on other place...

提交回复
热议问题