0
這是我的Python軟件的一部分來控制智能電視。我有功能「connection_status」。連接狀態功能給出錯誤並且不能正常工作
import fcntl, socket, struct
import base64
import time, datetime
import netifaces
from 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): // this is the function that does 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 TO TV", width=19, height=2, command = lambda: self.connection())
app = Application(root)
root.mainloop()
但是當我調用該函數,它輸出我這個錯誤:
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 exactly 1 argument (2 given)
即使電視斷開,狀態保持「連接」!
你是如何調用'connection_status'?該錯誤說你用一個額外的參數調用該函數,但該函數需要'self' – aschmid00
@jonrsharpe否,我不給任何參數。 – PepinCZ
@ aschmid00你,通過自我。添加到主帖。 – PepinCZ