python - Connection status function gives error and does not working right -
this part of python software control smart tv. have function "connection_status".
import fcntl, socket, struct import base64 import time, datetime import netifaces tkinter import * root = tk() root.title("pepin's samsung smart tv remote") root.geometry("391x595") #391 class application(): """pepin's samsung smart tv remote""" def __init__(self, master): self.master = master self.create_widgets() def connection(self): self.connection_status() def connection_status(self): // function not work right. try: connection_status = sock.recv(64) print("status: connected") self.label_connection_status['text'] = 'status: connected' except socket.timeout: connection_status = "" print("status: disconnected") self.label_connection_status['text'] = 'status: disconnected' self.master.after(1000, self.connection_status, self.master) def create_widgets(self): btn_connect = button(self.master, text = "connect tv", width=19, height=2, command = lambda: self.connection()) app = application(root) root.mainloop() but when call function, outputs me error:
status: connected exception in tkinter callback traceback (most recent call last): file "/usr/lib/python2.7/lib-tk/tkinter.py", line 1535, in __call__ return self.func(*args) file "/usr/lib/python2.7/lib-tk/tkinter.py", line 586, in callit func(*args) typeerror: connection_status() takes 1 argument (2 given) and if tv disconnects, status stay "connected"!
you calling self.connection_status line of code:
self.master.after(1000, self.connection_status, self.master) that result in following function call:
self.connection_status(self.master) however, connection_status doesn't accept arguments other self automatically added python. why getting error connection_status() takes 1 argument (2 given). self first argument, , self.master second argument, function designed accept self.
there never reason pass object attribute method of same object, since method has immediate access attributes. so, simple solution remove parameter after call:
self.master.after(1000, self.connection_status)
Comments
Post a Comment