Reputation: 189
I am creating a GUI using pythons Tkinter (I am using python 2.7 if it makes a difference). I wanted to add a table and so am using the tkintertable package as well. My code for the table is:
import Tkinter as tk
from tkintertable.Tables import TableCanvas
class createTable(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.F = tk.Frame(self)
self.F.grid(sticky=tk.N+tk.S+tk.E+tk.W)
self.createWidgets()
def createWidgets(self):
self.table = TableCanvas(self.F,rows=30,cols=30)
self.table.createTableFrame()
app = createTable()
app.master.title('Sample Table')
app.mainloop()
I would like to make the number of rows and columns seen change when I resize the frame. Currently there are 13 rows and 4 columns showing. I would like more to be seen when I make the window bigger. Any advice on how to achieve this would be greatly appreciated! Thank you so much for your help
Upvotes: 1
Views: 3734
Reputation: 2202
To achieve what you want to do, not much is needed.
The keyword here is grid_rowconfigure
and grid_columnconfigure
.
By default, grid rows to not expand after creation when the window size is changed. Using tk.Frame().grid_rowconfigure(row_id, weight=1)
this behavior changes.
The second thing you missed was that your createTable
class (please consider renaming it as it sounds like a function) is not set sticky.
import Tkinter as tk
from tkintertable.Tables import TableCanvas
class createTable(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
#########################################
self.master.grid_rowconfigure(0, weight=1)
self.master.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
self.grid(sticky=tk.NW+tk.SE)
#########################################
self.F = tk.Frame(self)
self.F.grid(row=0, column=0, sticky=tk.NW+tk.SE)
self.createWidgets()
def createWidgets(self):
self.table = TableCanvas(self.F,rows=30,cols=30)
self.table.createTableFrame()
app = createTable()
app.master.title('Sample Table')
app.mainloop()
should do the trick for you.
Upvotes: 2