我正在用tkinter和runpy在多个文件中编写登录页面。但是当我启动代码时,出现此错误:
File "C:\Users\grond\Desktop\Very Good Things\main_account_screen().py", line 4, in <module>
file_globals = runpy.run_path("Register_user().py")
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "Register_user().py", line 23, in <module>
Label(register_screen, text="Registrazione avvenuta con successo", fg="green", font=("Lemon/Milk", 11)).pack
NameError: name 'Label' is not defined
我尝试过from tkinter import *
这是第一个文件
from tkinter import *
import runpy
file_globals = runpy.run_path("Register_user().py")
file_globals = runpy.run_path("register().py")
def main_account_screen():
global main_screen
Button(text="Register", height="2", width="30", command=register).pack()
main_screen = Tk() #Crea finetra gui
main_screen.geometry("300x250")
main_screen.title("Login") #Titolo gui
#Form
Label(text="Login o Registrati", bg="blue", width="300", height="2", font=("Lemon/Milk", 13)).pack()
Label(text="").pack()
#Login Button
Button(text="Login", height="2", width="30").pack()
Label(text="").pack()
#Register Button
Button(text="Registrati", height="2", width="30").pack()
main_screen.mainloop() #Starta la GUI
main_account_screen() #Chiama la funzione
这是第二个
def register_user():
global username
global password
global username_entry
global password_entry
#Username e password
username_info = username.get()
password_info = password.get()
#aprire file in write mode
file = open(username_info, "w")
#scrittura info nel file
file.write(username_info + "\n")
file.write(password_info)
file.close()
username_entry.delete(0, END)
password_entry.delete(0, END)
Label(register_screen, text="Registrazione avvenuta con successo", fg="green", font=("Lemon/Milk", 11)).pack
Button(text="Login", height="2", width="30", command = login).pack
这是第三个
def register():
register_screen = Toplevel(main_screen)
register_screen.title("Registrazione")
register_screen.geometry("300x250")
#Variabili
username = StringVar()
password = StringVar()
Label(register_screen, text="Inserisci i dettagli qui sotto", bg="blue").pack()
Label(register_screen, text="").pack()
username_lable = Label(register_screen, text="Username * ")
username_lable.pack()
username_entry = Entry(register_screen, textvariable=username)
username_entry.pack()
password_lable = Label(register_screen, text="Password * ")
password_lable.pack()
password_entry = Entry(register_screen, textvariable=password, show='*')
password_entry.pack()
Label(register_screen, text="").pack()
Button(register_screen, text="Registrati", width=10, height=1, bg="blue").pack()
def login_verification():
print("working...")
要编写我使用Atom的代码