0

I am trying to create a timetabling app using Tkinter, and need to create a grid template, like the one below: Timetabling Template

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()
StudyAccount
  • 91
  • 1
  • 11
  • Have you seen [Creating a table look-a-like Tkinter](https://stackoverflow.com/q/11047803/7432)? – Bryan Oakley Oct 16 '19 at 19:06
  • Thank you for introducing me to that example, it certainly seems easier to follow, however I don't understand the following lines? shown in my edit – StudyAccount Oct 16 '19 at 19:34
  • ***`="black"`***: Change to `='red'` to see. [***`.grid_columnconfigure(...`***](http://effbot.org/tkinterbook/grid.htm#Tkinter.Grid.grid_columnconfigure-method), [***`Label.config-method`***](http://effbot.org/tkinterbook/label.htm#Tkinter.Label.config-method), [executing-modules-as-scripts](https://docs.python.org/3/tutorial/modules.html#executing-modules-as-scripts) – stovfl Oct 16 '19 at 20:20

0 Answers0