我在访问属于另一类的数据时遇到问题。我已经在该平台上找到了一些解决方案,但是仍然无法在脚本中实现。多谢您的协助。
我试图设计一个登录页面,包括用户名和密码。在用户填写完这些字段并单击“登录”按钮后,我想要从第1页获取这些变量以用于不同的功能(在def printName()
中打印)。
class Page(tk.Frame):
def __init__(self,*args,**kwargs):
tk.Frame.__init__(self,**kwargs)
def show(self):
self.lift()
class Page1(Page):
def __init__(self,**kwargs):
Page.__init__(self,**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,bg='white').place(x=15,y=201)
password= tk.Label(self,text="Password :",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",bg="red",command=close_window).place(x=180,y=450)
label.pack(side="top",fill="both",expand=True)
class Page2(Page):
def __init__(self,**kwargs)
label = tk.Label(self,bg="white")
button_2=tk.Button(self,text="Om Creation",width=10,command=OMcreat).place(x=750,y=400)
label.pack(side="top",expand=True)
class Page3(Page):
def __init__(self,**kwargs):
Page.__init__(self,**kwargs)
label = tk.Label(self,text="")
label.pack(side="top",expand=True)
class MainView(tk.Frame):
def __init__(self,**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",expand=True)
p1.place(in_=container,x=0,y=0,relwidth=1,relheight=1)
p2.place(in_=container,relheight=1)
p3.place(in_=container,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",expand=True)
root.mainloop()
def close_window():
root.destroy()
driver.close()
def printName():
print(last_user_name)