Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to access an instance variable in another class in python

$
0
0

I am writing a program that is utilizing multiple classes. I have one class that is dedicated to determining values for a set of variables and a py file have an instance of class login. I would then like to be able to access the values of those variables with other classes. My code looks as follows:

main.py:

import logindef main():    root = tk.Tk()    login.Login(root)

login.py:

import adminclass Login:    def __init__(self , root):        self.root = root        self.var1= tk.StringVar()    def loginFunc(self):        self.var3= tk.Entry(self, textvariable=self.var1) #var1 get value through tkinter form        admin.AdminControls(self.root)

admin.py:

import loginclass AdminControls:    def __init__(self, root):        self.root = root        self.adminControlsFrame()    def adminControlsFrame(self):        self.labelName= Label(self.entriesFrame, text="welcome"+var1) #this is where I want to use var1

I have 7 variables in login class just as same as var1 and I need to use them all in admin.

should I just pass them all as function arguments (like admin.AdminControls(self.root, var1, var2, var3, ..)) or is there a cleaner way?

I have read Use or access class instances directly in another class in Python, but the problem is my classes are in different files.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>