0
from tkinter import *
from tkinter import ttk

class Vault:
    def __init__(self, root):
        set_pass = 'hello'
        if set_pass!='':      
            self.root = root
            self.root.title("Password Vault")
            self.root.geometry("350x150+500+260")
            color = 'black'
            text_color = '#f3ca20'

            title = Label(self.root, text="Password Vault", bd=2, font=("times new roman", 20, "bold"), bg=color, fg=text_color)
            title.pack(fill=X)

            pass_txt = Label(self.root, text="Password: ", bd=2, font=("times new roman", 18), bg=color, fg=text_color)
            pass_txt.place(x=10, y=60)

            self.pass_entry = Entry(self.root, font=("times new roman", 15, "bold"), bd=5)
            self.pass_entry.place(x=130, y=60)

            okbtn = Button(self.root, text="OK", command=self.loginfunc)
            okbtn.place(x=280, y=110)

        else:       
            pass

    def loginfunc(self):
        if self.pass_entry.get()=='hello':
            displayinfo = Toplevel()
            displayinfo.title("Password Vault")
            displayinfo.geometry("700x400+500+260")
            color = 'black'
            text_color = '#f3ca20'

            user_tb_frame = Frame(displayinfo, bd=4, relief=RIDGE, bg='BLACK')
            user_tb_frame.place(x=5, y=10,  height=600, width=683)

            #treeview to display data
            user_tb = ttk.Treeview(user_tb_frame, columns=("Email", "Password", "Website","Remark"))
            user_tb.pack(fill=BOTH)   #### It doesn't fill the Y-axis

            displayinfo.mainloop()

        else:
            print('pass not matched')


root = Tk()
v = Vault(root)
root.mainloop()

I'm using user_tb.pack(fill=BOTH) but it is not working, it doesn't fill the Y-axis completely. But if I use user_tb.pack(fill=BOTH, expand=1) then it works just fine.

So, is it necessary to use expand everytime with fill and if not then why it isn't working without using the expand=1?

And how to close the root window when Toplevel window starts?

martineau
  • 119,623
  • 25
  • 170
  • 301
Manish Gusain
  • 35
  • 1
  • 7
  • 1
    Expand is necessary because `fill = BOTH` will only fill only the size of the window that is visible to you when the window is first opened. However, `expand=True` makes your UI dynamic. That is it will keep on filling the X and Y axis even when the user resizes the window. –  Oct 04 '20 at 19:18
  • 1
    @NeoNØVÅ7 Thanks a lot for your help. Pls also tell me how to close the root window when the toplevel window starts. – Manish Gusain Oct 05 '20 at 07:15
  • 1
    You can see this [solution](https://stackoverflow.com/a/54245391/13786942) –  Oct 05 '20 at 07:59
  • 1
    Thanks again @NeoNØVÅ7 – Manish Gusain Oct 06 '20 at 08:49

0 Answers0