So, I have been having trouble figuring out what does return
do when used for tkinter widgets
here are 3 blocks of code that have the same result, and I wasn't sure what their difference is and whether they differ in performance, and finally, which one is the standard approach
1
import tkinter as tk
class App:
def __init__(self):
window = tk.Tk()
self.label_in_window(window, text = "hello world!")
window.mainloop()
def label_in_window(self, parent, text):
return tk.Label(parent, text = text).pack()
App()
2
import tkinter as tk
class App:
def __init__(self):
window = tk.Tk()
self.label_in_window(window, text = "hello world!")
window.mainloop()
def label_in_window(self, parent, text):
tk.Label(parent, text = text).pack()
return
App()
3
import tkinter as tk
class App:
def __init__(self):
window = tk.Tk()
self.label_in_window(window, text = "hello world!")
window.mainloop()
def label_in_window(self, parent, text):
tk.Label(parent, text = text).pack()
App()