简体   繁体   English

Tkinter Window 从 A Function 调用时未打开

[英]Tkinter Window Not Opening When Called From A Function

I have 2 different windows that I want to open from the Login page, Home Page, and Create User.我有 2 个不同的 windows 我想从登录页面、主页和创建用户打开。 Create user functions just as I want it to, but clicking the button to login doesn't open main like I want it to.按照我的意愿创建用户功能,但是单击登录按钮并没有像我希望的那样打开 main。 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.在没有 function 的情况下运行 MainPage.py 会像我想要的那样打开 window,但是从 Login.py 调用打开的 function 什么也没做。

Login.py:登录.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主页.py

import tkinter as tk


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

When you import a file / module and you want to call any function in that file you need to use parentheses().当您导入一个文件/模块并且您想调用该文件中的任何 function 时,您需要使用括号()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM