简体   繁体   中英

How to access variable of a function in one python file in another python file

Python file 1 login.py

def login_screen():
    username_text = tk.Entry(frame2,textvariable = username_var, width=15,font = 'Times 25')
login = tk.Tk()

Python file 2 packages.py

def package_screen():
    username = login.username_text.get()
packages = tk.Tk

Cannot find reference 'username_text' in 'login.py'

I want to get the username entered by the user in file 1 I keep getting this error

AttributeError: 'function' object has no attribute 'username_text' Does anyone know what it means????

I am not exactly sure what you want but I guess you need to import login.py.

import login as lgn

def package_screen():
    username = lgn.login.username_text.get()
packages = tk.Tk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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