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.
Problem is that when I press a button, in its place, I need to create free space and move that button to space that was empty before, and I cannot do that because I don't know how to get grid (x and y axes) information of pressed button to use it to create free space.
This is my current code:
from Tkinter import *
#Input:
n=int(raw_input("Input whole positive number: "))
L = range(1,n+1)
k = n
m = n
#Program:
root = Tk()
for i in L:
for j in L:
frame = Frame(root)
frame.grid(row = i, column = j)
if j == k and i == m:
pass
else:
button = Button(frame)
button.grid(row = i, column = j)
root.mainloop()
It would be something like this, where I wanted to get button grid position, and use it to change k
and m
variables to make empty space in position where pressed button was.