我正在使用pythons Tkinter创建一个GUI(如果它有所不同,我正在使用python 2.7)。我想添加一张桌子,所以我也使用了tkintertable包。我的表格代码是:
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()
我想在调整框架大小时改变行和列的数量。目前显示有13行和4列。当我把窗户做得更大时,我希望看到更多。如何实现这一点的任何建议将不胜感激! 非常感谢你的帮助
答案 0 :(得分:1)
要实现你想做的事,不需要太多。
此处的关键字为grid_rowconfigure
和grid_columnconfigure
。
默认情况下,当窗口大小更改时,网格行在创建后不会展开。使用tk.Frame().grid_rowconfigure(row_id, weight=1)
此行为会发生变化。
你错过的第二件事是你的createTable
课程(请考虑重命名,因为它听起来像一个功能)没有设置粘性。
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()
应该为你做的伎俩。