1

Why does tk.Tk.__init__(self, *args, **kwargs) open a new window and what does the parameters inside it do?

for example:

import tkinter as tk


class App(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        tk.Label(self, text='text on the screen').pack()


app = App()
tk.mainloop()

edit: I wasn't really asking what *args and **kwargs do I mainly wanted to know what tk.Tk.__init__(self) does!

Juho Pesonen
  • 105
  • 1
  • 2
  • 9

1 Answers1

0

When you create a new App object, it will have arguments. An example of an app object may be X = App("Flappy Bird", "iPhone", 10). init(self): Self is required as the first argument for all object initializations. This is so that Python knows which object is being referred to if you have multiple App objects. For example, if you have another Y = App("Youtube", "Android", 11), then instead of referring to X.appname or Y.appname, you are just saying to use the one that belongs to the object. *args is used to pass in all of the arguments if you have a lot of them. When using dictionaries, *args will only pass through all of the keys. If you want all of the values of a dictionary to be passed through, you use **kwargs.