У меня проблема с доступом к данным другого класса. Я нашел некоторые решения на этой платформе, но все же не смог реализовать это в своем скрипте. Я буду признателен за вашу помощь в этом.
Я пытался создать страницу входа, включая имя пользователя и пароль. После того, как пользователь заполнит эти поля и нажмет кнопку входа в систему, я хочу получить эти переменные (со страницы 1) для использования в различных функциях (печать в def printName()
).
class Page(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
def show(self):
self.lift()
class Page1(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs,bg='white')
label = tk.Label(self, text="",bg='white')
heading= tk.Label(self, text="ENTER OM", font=("ALGERIAN",40,"bold"), fg="black",bg='white').pack()
user_name= tk.Label(self, text="User Name :", font=("arial",20,"bold"), fg="black",bg='white').place(x=15,y=201)
password= tk.Label(self, text="Password :", font=("arial",20,"bold"), fg="black",bg='white').place(x=15,y=305)
self.shared_data = {"last_user_name": tk.StringVar(),"password": tk.StringVar()}
entry1 = tk.Entry(self, textvariable=self.shared_data["last_user_name"]).place(x=210, y=214)
last_user_name = self.shared_data["last_user_name"].get()
button_1=tk.Button(self,text="Log In", width=12,height=3,fg="white",bg="blue",font=("Arial",10), command=printName).place(x=350,y=450)
button_3=tk.Button(self,text="Close", width=12,height=3,fg="white", bg="red", font=("Arial",10),command=close_window).place(x=180,y=450)
label.pack(side="top", fill="both", expand=True)
class Page2(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = tk.Label(self, text="", bg="white")
button_2=tk.Button(self,text="Om Creation", width=10,height=3 ,fg="white",bg="blue",font=("Arial",10), command=OMcreat).place(x=750,y=400)
label.pack(side="top", fill="both", expand=True)
class Page3(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = tk.Label(self, text="")
label.pack(side="top", fill="both", expand=True)
class MainView(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
p1 = Page1(self)
p2 = Page2(self)
p3 = Page3(self)
buttonframe = tk.Frame(self)
container = tk.Frame(self)
root.configure(bg='white')
buttonframe.pack(side="top", fill="x", expand=False)
container.pack(side="top", fill="both", expand=True)
p1.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
p2.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
p3.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
b1 = tk.Button(buttonframe, text="Page 1", command=p1.lift)
b2 = tk.Button(buttonframe, text="Page 2", command=p2.lift)
b3 = tk.Button(buttonframe, text="Page 3", command=p3.lift)
b1.pack(side="left")
b2.pack(side="left")
b3.pack(side="left")
p1.show()
if __name__ == "__main__":
root = tk.Tk()
root.title("OM credantials")
root.wm_geometry("1000x750+0+0")
root.configure(bg='white')
main = MainView(root)
main.pack(side="top", fill="both", expand=True)
root.mainloop()
def close_window():
root.destroy()
driver.close()
def printName():
print(last_user_name)