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

Time:01-12

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()

CodePudding user response:

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

  • Related