Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

How autonomous should the target be left after the merger deal?

Answered: 1 week ago