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('
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started