My current code is found at the bottom
I am trying to close Window1 after successful log in has been made and open Window2
Currently I have username entry only just for test purposes.
My current if statement opens up new window if one is the username Entry. But two windows are displayed.
I need to get rid of Window 1 and just show Window 2 after successful log in.
I have done some research and found this answer but I don't think this is functional with my current code.
I also tried the following but an error shows up:
def login_system(self):
u = self.UsernameEntry.get()
if u == "one":
self.newWindow = Toplevel(self.master)
self.app = Window2(self.newWindow)
Window1().destory()
Error :
TypeError: __init__() missing 1 required positional argument: 'master'
How can I achieve this?
from tkinter import *
from tkinter import DISABLED, messagebox
import tkinter.ttk as ttk
import os
import glob
from PIL import Image, ImageTk, ImageGrab
from pathlib import Path
import pyautogui
import time
def main():
root = Tk()
app = Window1(root)
root.mainloop()
class Window1:
def __init__(self,master):
self.master = master
self.master.title("User Log In")
self.master.geometry('1000x750')
self.frame = Frame(self.master)
self.frame.pack(fill="both", expand=True)
self.UsernameEntry = Entry(self.frame)
self.UsernameEntry.grid(row = 2, column = 0)
self.btnLogin = Button(self.frame, text = 'login', width = 17, command = self.login_system)
self.btnLogin.grid(row = 3, column = 0)
def login_system(self):
u = self.UsernameEntry.get()
if u == "one":
self.newWindow = Toplevel(self.master)
self.app = Window2(self.newWindow)
else:
self.UsernameEntry.delete(0,"end")
class Window2:
def __init__(self,master):
notebook = ttk.Notebook(master)
notebook.pack(expand = 1, fill = "both")
#Frames
main = ttk.Frame(notebook)
manual = ttk.Frame(notebook)
notebook.add(main, text='Main-Screen')
notebook.add(manual, text='Manual')
if __name__ == '__main__':
main()