这是一个使用 Tkinter 设计顶层窗口的类 该问题来自尝试从成员 self.lbox 获取信息但不被识别为成员的方法。错误是: NameError:名称“self”未定义
附加问题:我相信我可以删除成员声明中的所有“self”前缀。我说得对吗?
class Fen_Radioweb(Toplevel):
"Fenêtre satellite contenant des contrôles de redimensionnement"
def __init__(self, **Arguments):
Toplevel.__init__(self, **Arguments)
global window_height
global window_width
global x_cordinate
global y_cordinate
self.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
self.content1 = ttk.Frame(self)
self.content1.grid(column=0, row=0)
self.led_1=ttk.Button(self.content1, text='play',command=lambda:player.play())
self.led_1.grid(column=1, row=0)
self.led_2=ttk.Button(self.content1, text='stop',command=lambda:player.stop())
self.led_2.grid(column=1, row=1)
self.lbox=Listbox(self.content1, height=5,listvariable=cnames)
self.lbox.bind('<Double-1>', self.change_channel)
self.lbox.grid(column=2, row=2)
def change_channel(*args):
idxs = self.lbox.curselection()
idx = int(idxs[0])
global channel_ini
channel_ini=idx
url=liste_url[idx]
media=instance.media_new(url)
player.set_media(media)
player.play()
我试图删除 idxs = self.lbox 中的 self... 我尝试将 (*args) 替换为 (self) 不成功
您在函数声明中缺少
self
参数:
def change_channel(self, *args):
# Here---------^