in Education by
Ok so my problem is that when calling a method inside of my class from outside(top level), it takes the self parameter as if it would be an argument that it wants a value for, my class: class Client: def __init__(self, host='localhost', port=5000): try: self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server_socket.connect((host, port)) info.set("Connected...") self.boool = True self.gotten = "" self.data = "" b1.config(state=NORMAL) b2.config(state=NORMAL) textEntry.config(state=NORMAL) time.sleep(1) threading.Timer(1.0, self.listen).start() except socket.error as error: self.boool = False info.set(str(error)[14:]) except: self.boool = False info.set("An unknown error occured") def leave(self): self.boool = False self.server_socket.close() b1.config(state=DISABLED) b2.config(state=DISABLED) textEntry.config(state=DISABLED) def listen(self): while self.boool == True: time.sleep(0.1) self.data = self.server_socket.recv(512) if self.data == bytes('quit', 'UTF-8'): self.leave() print("Server has left the chat") elif self.data != self.gotten: v.set("Server: %s\n%s" % (self.data, v.get())) self.gotten = self.data def send(self, message=''): self.data.send(bytes(message, 'UTF-8')) v.set("Client: %s\n%s" % (message, v.get())) And my tkinter buttons that calls the Client class and one that calls the method leave(): b2 = Button(root, text="Leave", width=8, state=DISABLED, command=Client.leave) b2.grid(row=0, column=3) Button(root, text="Connect", width=8, command=Client).grid(row=0, column=4) And the error: Traceback (most recent call last): File "C:\Python32\chatClient2.py", line 68, in b2 = Button(root, text="Leave", width=8, state=DISABLED, command=Client.leave) TypeError: leave() takes exactly 1 argument (0 given) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The client instance is supposed to be created when the user presses the "Connect" button, so let it call a method GUI.connect, which creates self.client=Client(). Then use a second method GUI.leave, which when called, delegates to self.client.leave(): class GUI(): def __init__(self): self.client = None def setup_buttons(self): self.b1 = ... self.b2 = Button(root, text = "Leave", width = 8, state = DISABLED, command = self.leave) b2.grid(row = 0, column = 3) Button(root, text = "Connect", width = 8, command = self.connect).grid(row = 0, column = 4) def connect(self): self.b1.config(state = NORMAL) self.b2.config(state = NORMAL) self.client = Client() def leave(self): if self.client: self.b1.config(state = DISABLED) self.b2.config(state = DISABLED) self.client.leave()

Related questions

0 votes
    A random variable X takes the values 0,1,2,3,..., with prbability PX(=x)=k(x+1)( 1 5 )x, where k is a ... 16 25 C. 18 25 D. 19 25 Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
0 votes
    A random variate X takes the values 0, 1, 2, 3 and its mean is 1.3. If `P(X= 3) = 2P(X= 1)` and `P(X= 2) = ... `0.2` C. `0.3` D. `0.4` Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
0 votes
    You remove four fresh tobacco leaves of similar size and age. Leave leaf 1' as it is, smear leaf 2' ... be drawn from this experiment Select the correct answer from above options...
asked Nov 9, 2021 in Education by JackTerrance
0 votes
    Solve the following puzzle You are going to visit your grandmother on Mother's day. You want to give her two cakes. ... you leave with to be able to give your grandmother 2 cakes...
asked Feb 12, 2021 in Education by JackTerrance
0 votes
    I want to create a new list from the existing two lists that will have all the matches from list 2 which has an exact ... *", i) in a] Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    I can't decipher however the sklearn.pipeline.Pipeline works precisely. Some explanation in this documentation. What ... estimator)]) Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Please tell me what random.seed() does in Python. For example, why do the below trials do what they do ( ... randint(1, 10) 7 Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Python - What is exactly sklearn.pipeline.Pipeline?...
asked Nov 20, 2020 in Education by Editorial Staff
0 votes
    What will be the output of the following Python code? >>>list1 = [1, 3] >>>list2 = list1 >>>list1[0] = 4 >>>print(list2) a) [1, 4] b) [1, 3, 4] c) [4, 3] d) [1, 3]...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    I have a big data frame. I want to replace float 1.0 and 0.0 with the true and false. My code: import pandas ... to do it in one line. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Calculate the EMF of the cell in whiCHM the following reaction takes place : Ni(s)+2Ag⊕(0.002M)→Ni2+(0.160M)+2Ag(s) Select the correct answer from above options...
asked Jan 5, 2022 in Education by JackTerrance
...