I don't know why the UI is not showing when im using self.root.geometry in python

Question:

So I just started my FYP project and I followed the code online and for some reason the UI won’t show up and no error is shown in my code editor. when I use root.geometry it works fine but when there is a self.root.geometry the UI just wont show up. Please help, I’m new to python so…

I’ve tried other geometry code without self. in it and it works fine, but when the self. is added nothing shows up. I just want the UI to show up…
Here is my code.

from tkinter import*
from tkinter import ttk
from PIL import Image,ImageTk

class Face_Recognition_System:
    def __init__(self,root):
        self.root=root
        self.root.geometry("1530x790+0+0")
        self.root.title("Face Recognition System")


        if __name__ == "__main__":
            root=Tk()
            obj=Face_Recognition_System(root)
            root.mainloop()
Asked By: CatJeff

||

Answers:

Try this. if __name__ == "__main__": should be outside.

from tkinter import*
from tkinter import ttk
#from PIL import Image,ImageTk

class Face_Recognition_System:
    def __init__(self,root):
        self.root=root
        self.root.geometry("1530x790+0+0")
        self.root.title("Face Recognition System")


if __name__ == "__main__":
    root=Tk()
    obj=Face_Recognition_System(root)
    root.mainloop()

Output:

enter image description here

Answered By: toyota Supra
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.