I am trying to create a timetabling app using Tkinter, and need to create a grid template, like the one below:
I looked up some examples from StackOverflow (such as Tkinter | Custom widget: Infinite (horizontal) scrolling calendar ) but am struggling to grasp the OOP use.
Are there any simpler ways to implement this table in tkinter? Or are there any ways to use a 'simpler'(?) method of OOP to develop the timetable?
Thanks
Update
I've looked through the example: It is easier to follow, but would it be possible to explain the starred line from the code?
import Tkinter as tk
class ExampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
t = SimpleTable(self, 10,2)
t.pack(side="top", fill="x")
t.set(0,0,"Hello, world")
class SimpleTable(tk.Frame):
def __init__(self, parent, rows=10, columns=2):
# use black background so it "peeks through" to **
# form grid lines
tk.Frame.__init__(self, parent, background="black")
self._widgets = []
for row in range(rows):
current_row = []
for column in range(columns):
label = tk.Label(self, text="%s/%s" % (row, column),
borderwidth=0, width=10)
label.grid(row=row, column=column, sticky="nsew", padx=1, pady=1)
current_row.append(label)
self._widgets.append(current_row)
for column in range(columns):
self.grid_columnconfigure(column, weight=1) **
def set(self, row, column, value):
widget = self._widgets[row][column] **
widget.configure(text=value) **
if __name__ == "__main__": **
app = ExampleApp()
app.mainloop()