Issue
I'm just learning Python. There was a problem that I still couldn't understand. How to pass self.login_field.get() from the Conectad class to the Query Class
class Connectad(Frame): #Фрейм окна логина и пароля
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.parent = parent
Label(self,text='Логин:').grid(row=0)
self.login_field = Entry(self,width=30)
self.login_field.grid(row=0,column=1)
Label(self,text='Пароль:').grid(row=1)
self.pw_field = Entry(self,show = '*', width=30)
self.pw_field.grid(row=1,column=1)
self.notlogon = Label(self,text='Не верный логин или пароль',fg='red', font=("Arial", 14))
self.notlogon.grid_remove
send_button = Button(self, text='Отправить',bg='#4a7abc',
fg='yellow',
activebackground='green',
activeforeground='white',command=self.validationlogin).grid(row=3, column=2, sticky=W, pady=4)
def connad(self): # Подключение к AD
self.AD_SERVER = 'dc.local'
self.AD_USER = self.login_field.get()
self.AD_PASSWORD = self.pw_field.get()
self.AD_SEARCH_TREE = 'dc=dc,dc=local'
self.AD_SEARCH_OU = 'ou=USERS,dc=dc,local'
self.server = Server(self.AD_SERVER, use_ssl=True)
self.conn = Connection(self.server,user=self.AD_USER,password=self.AD_PASSWORD)
print(self.conn.bind)
if not self.conn.bind():
print('False')
elif self.conn.bind():
#print(self.conn)
self.parent.switch_frame(Query)
return self.conn
def user(self):
self.logi = self.login_field.get()
print(self.logi)
return self.logi
Need to be sent here:
class Query(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.parent = parent
def adoffice(self): # Создание пользователя офис
get = Connectad()
get.user()
print(get.logi)
Parent class:
class App(Tk): def init(self): Tk.init(self) self._frame = None self.switch_frame(Connectad)
def switch_frame(self, frame_class): new_frame = frame_class(self) if self._frame is not None: self._frame.destroy() self._frame = new_frame self._frame.pack()
What can you recommend?
Solution
Based on your updated code, suggest to pass the user name to class Query
:
class Connectad(Frame):
...
def connad(self):
...
elif self.conn.bind():
# pass input user name to class Query
self.parent.switch_frame(Query, user=self.login_field.get())
...
class Query(Frame):
def __init__(self, parent=None, *args, **kwargs):
super().__init__(parent)
self.parent = parent
# get the user name using keyword argument "user"
self.user = kwargs.get("user")
print(self.user)
class App(Tk):
...
def switch_frame(self, frame_class, *args, **kwargs):
if self._frame is not None:
self._frame.destroy()
self._frame = frame_class(self, *args, **kwargs)
self._frame.pack()
Note that destroying current frame and then creating the new frame is not a good design on switching frame. Suggest to search StackOverflow on questions about switching frames.
Answered By - acw1668
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.