0

I don't understand what does comma after variable, self.label = Label(master, text = 'This is our first GUI!') in this code master is a variable but why it is here and why there is a comma after master variable and how this line works?

Here is the full code

from tkinter import Tk, Label, Button

class MyFirstGUI:
    def __init__(self, master):
        self.master = master
        master.title("A Simple GUI")

        self.label = Label(master, text = 'This is our first GUI!')
        self.label.pack()

        self.greet_button = Button(master, text = 'Greet', command = self.greet)
        self.greet_button.pack()

        self.close_button = Button(master, text='close', command = master.quit)
        self.close_button.pack()

    def greet(self):
        print("Hello User!!!")

root = Tk()
my_gui = MyFirstGUI(root)
root.mainloop()

Can someone explain how these lines work?

self.label = Label(master, text = 'This is our first GUI!'),
self.greet_button = Button(master, text = 'Greet', command = self.greet),
 self.close_button = Button(master, text='close', command = master.quit)

The exact thing I need to know is how master, text='blah blah', blah blah thing work , is it assign text = 'blah blah' to master variable?

  • Do you have any experience how function calls in Python or similar languages work? Did you read up on what Label and Button do? – MisterMiyagi Dec 21 '19 at 07:22
  • comman may have different meaning in different places. In function it seperates arguments. In other places it can create tuple. – furas Dec 21 '19 at 07:24
  • Similar to how you have defined a class MyFirstGUI with constructor __init__ accepting master as the parameter, Label would be a class which accepts the root widget element as the fist argument and the second argument to it would accepts variable length list of argument (**kwargs) which in this cases is creating a label of type text with the value "This is our first GUI!". You might want to go thorough the docs for tkinter and be able to get to know better on the methods and the parameters accepted – Varun Dec 21 '19 at 07:37
  • `master` and `text="close"` are two arguments send to `Button` and one arguments has nothing to do with other argument. – furas Dec 21 '19 at 07:42

1 Answers1

0

Any control must known his windows or container parent, then Label(master,text="blah blah blah" it"s a label on window master. button(master. ..) it's a botón inside master window.