-1

I am new to the Python universe. I am learning to use language. I would like to learn how create a table space within an application. I would like to understand the following code (available at https://pandastable.readthedocs.io/en/latest/examples.html), in particular some parts such as:

1 - Why did "Frame" enter parentheses: "TestApp (Frame)"?

2 - Why was init called after Frame: Frame .__ init __ (self)?

3 - I didn't understand the reason for the relationship: self.main = self.master.

4 - In app.mainloop (), why app? Usually we use the main window, but app is not window, before it is calling the class.

Code:

from tkinter import *
from pandastable import Table, TableModel

class TestApp(Frame):
        """Basic test frame for the table"""
        def __init__(self, parent=None):
            self.parent = parent
            Frame.__init__(self)
            self.main = self.master
            self.main.geometry('600x400+200+100')
            self.main.title('Table app')
            f = Frame(self.main)
            f.pack(fill=BOTH,expand=1)
            df = TableModel.getSampleData()
            self.table = pt = Table(f, dataframe=df,
                                    showtoolbar=True, showstatusbar=True)
            pt.show()
            return

app = TestApp()
#launch the app
app.mainloop()
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Leonardo
  • 120
  • 9
  • ***"I would like to learn how create a table"***: This is a bad pice of code, don't use it as template or to learn. There are couple problems here. Read [Best way to structure a tkinter application](https://stackoverflow.com/a/17470842/7414759) – stovfl Jan 04 '20 at 22:13
  • 1
    Please do not edit-war on this post. See the remarks I have made on your other two questions. If you still have queries about editing policy here, please ping me and wait for a discussion first. – halfer Jan 04 '20 at 23:43

1 Answers1

1
  1. Why did "Frame" enter parentheses: "TestApp (Frame)"? This way Python of declaring that the class TestApp inherits from the class Frame. If you are not familiar with Object-Oriented Programing: it means that TestApp is a new type of Frame, it will have all the attributes and functionalities of Frame, plus new things that can be implemented in the code block below it. Anyway, I would suggest you to read more on OOP, which is a large topic, to understand the above code.

  2. Why was init called after Frame: Frame .__ init __ (self)? Frame.__init__(self) means it will call the initialization function of the Frame class. Since TestApp is a Frame, it inherits the Frame initialization function, and this is how you call such function.

  3. I didn't understand the reason for the relationship: self.main = self.master, self.master is the parent Frame of the current app. This assignment assigns the master to the variable main

  4. In app.mainloop (), why app? Usually we use the main window, but app is not window, before it is calling the class. app here is an instance of TestApp, which means it is also an instance of Frame

9mat
  • 1,194
  • 9
  • 13