I am trying use object oriented programming style to write the code for a Tkinter app. I want to use a class method to place labels(or other widgets) to the GUI. The code I wrote is adding a character which I don't expect to the GUI. How can I write the initial add_label method so that it does not add the unwanted character. Below is my code and a screenshot. I am new to OOP, so i might be missing something.
from tkinter import *
class App:
def __init__(self, parent):
self.widgets(root)
self.add_label(root)
def widgets(self, app):
self.title = Label(app, text= 'LABEL UP').pack()
self.btn = Button(app, text = 'BUTTON').pack()
def add_label(self, text):
Label(text= text).pack()
root = Tk()
App(root)
App.add_label(root, 'LABEL_1')
App.add_label(root,'LABEL_2')
root.mainloop()
I am new to OOP and stil trying to figure out how i can benefit from code reuse in this case. My app has several widgets and functions
self.add_label(root).