如何从另一个类访问变量?

时间:2018-07-25 15:23:01

标签: python-3.x tkinter tkinter-entry

我需要从另一个类访问变量,但不确定如何操作。这就是我现在得到的:

class NewEmployee:
    def __init__(self, master): #Here i've made some entry points for users to enter data

        self.master = master
        self.master.title("Jans Corp")
        self.master.configure(background="lightgrey")
        self.master.geometry("300x500")

        self.FirstNameEntry = tk.Entry(self.master)
        self.SurnameEntry = tk.Entry(self.master)
        self.AgeEntry = tk.Entry(self.master)
        self.PostcodeEntry = tk.Entry(self.master)
        self.WageEntry = tk.Entry(self.master)
        self.EmailEntry = tk.Entry(self.master)
        self.HoursEntry = tk.Entry(self.master)

我正在尝试在另一个类中获取“ FirstNameEntry”和“ SurnameEntry”,因此我可以获取用户输入的数据。

class MainPageGUI:
    def __init__(self, master, class_NewEmployee): #Here i've made another class where i'd like to use the variables. 

        self.master = master
        self.master.title("Jans Corp")
        self.master.configure(background='lightgrey')
        self.master.geometry("1200x800")

    def InfoAdd(self):
        if class_NewEmployee.FirstNameEntry.get() == " " and class_NewEmployee.SurnameEntry.get() == " ":
            print("Fill in all boxes!")
        else:
            print("Employee added!")
            self.master.after(30, lambda: [self.DisplayData()])

    def AddNewEmployee(self):
        self.rootNewEmployee = tk.Toplevel(self.master)
        self.AddEmployeePage = NewEmployee(self.rootNewEmployee)

我从另一篇文章中读到,我必须将类“ NewEmployee”的实例传递给我想在其中使用变量的类。我了解这个概念,但不太了解代码。

这是我正在谈论的帖子:How would I access variables from one class to another?

class_NewEmployee是我尝试制作帖子所指示的“实例”,但是它似乎没有用。

任何帮助将不胜感激!

0 个答案:

没有答案