Home > Net >  Tkinter Window Not Opening When Called From A Function
Tkinter Window Not Opening When Called From A Function

Time:01-31

I have 2 different windows that I want to open from the Login page, Home Page, and Create User. Create user functions just as I want it to, but clicking the button to login doesn't open main like I want it to. I don't get an error message, it just sits there and does nothing. Running MainPage.py without the function opens the window just like I want it to, but calling the open function from Login.py does nothing.

Login.py:

from traceback import print_tb
from tkinter import *
from tkinter import ttk
import tkinter as tk
from traceback import print_tb
import CreateUser
import HomePage

#instantiate login screen
login_screen = tk.Tk()
login_screen.state('zoomed')
login_screen.title("Login")

#Input box labels
tk.Label(login_screen, text="Login").place(relx=0.5, rely=0.35,anchor=CENTER)
tk.Label(login_screen, text="Password").place(relx=0.5, rely=0.45,anchor=CENTER)

#Input boxes
login_entry = tk.Entry(login_screen)
login_entry.place(relx=0.5, rely=0.4, anchor=CENTER)
password_entry = tk.Entry(login_screen, show="*")
password_entry.place(relx=0.5, rely=0.5, anchor=CENTER)

#Stored Login & Password
userpass = open("UserPass.txt","r ")
content = userpass.readlines

#check username and password, then launch new window
def open_main():
    for line in open("UserPass.txt","r").readlines(): # Read the lines
        login_info = line.split() # Split on the space, and store the results in a list of two strings
        if login_entry.get() == login_info[0] and password_entry.get() == login_info[1]:
            HomePage.open
        else: print("Fail")

#login button to call main screen
Button(login_screen, text="Login", command=open_main).place(relx=0.5, rely=0.55, anchor=CENTER)

#Send to change login screen
Button(login_screen, text="Change Login", command=CreateUser.User_Create).place(relx=0.5, rely=0.6, anchor=CENTER)

login_screen.mainloop()

HomePage.py

import tkinter as tk


def open():
    root = tk.Tk()
    root.mainloop()

CodePudding user response:

When you import a file / module and you want to call any function in that file you need to use parentheses().

  •  Tags:  
  • Related