Question: I am self-studying Python tkinter right now and want to seperate a tkinter program into multiple .py files but I don't know how to do

I am self-studying Python tkinter right now and want to seperate a tkinter program into multiple .py files but I don't know how to do so.

Below is a workable sample code, can you show me how to seperate it? The program launches a login window and once entered the correct username and password it will redirect to the main page. I want to seperate it into 3 .py files: root.py(for Main Window), login.py(for Login Window), main.py(where I would run my program here)

Sample code:

from tkinter import * import sys

def exit(): topWindow.destroy() rootWindow.destroy() sys.exit()

def login(event): if entry1.get() == 'admin' and entry2.get() == 'admin': rootWindow.deiconify() topWindow.destroy()

rootWindow = Tk() topWindow = Toplevel()

topWindow.geometry('300x260') topWindow.title('Login Screen') topWindow.config(background='white') rootWindow.title('Main Page') rootWindow.geometry('855x650') rootWindow.config(background='white') rootWindow.withdraw()

label1 = Label(topWindow, text='Username:') entry1 = Entry(topWindow) label2 = Label(topWindow, text='Password:') entry2 = Entry(topWindow, show='*') entry2.bind('', login) buttonExit = Button(topWindow, text='Exit', command=lambda:exit()) buttonLogin = Button(topWindow, text='Log in', command=lambda:login(None))

label1.pack() label2.pack() entry1.pack() entry2.pack() buttonExit.pack() buttonLogin.pack()

rootWindow.mainloop()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!