0

For example, I am trying to create a greetings Label that says "Welcome to ..." so is it better to do:

def main():
    greeting = Label(root, text="Welcome to tictactoe! Player1 choose your letter:")
    greeting.grid(row=0, column=0)

or include the Label outside of the function because it will only be used once like this and call it as needed:

def main():
    greeting.grid(row=0, column=0)

greeting = Label(root, text="Welcome to tictactoe! Player1 choose your letter:")

Also, should we do root.mainloop() before or after main()?

Sproll
  • 1
  • 1
  • I think it's better to use the first one only if you won't interact with label in another functions. And about ```root.mainloop``` of course you should do it after main function – crackanddie Jan 16 '21 at 19:56
  • It's impossible to answer with such a simple example. Plus, you're asking for opinions which is off topic for Stackoverflow. That being said, in most cases you should lay out the widgets in the same scope that they were created. There are plenty of exceptions to that rule, however. – Bryan Oakley Jan 16 '21 at 20:40

0 Answers0