this is a class for designing a toplevel window with Tkinter the issue comes from the method which tries to get an info from the member self.lbox but it is not recognized as a member. the error is : NameError: name 'self' is not defined
additional question : I believe I can remove all 'self' prefixes in the member declaration. Am I correct ?
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()
I tried to remove self in idxs = self.lbox.... I tried to replace (*args) with (self) unsuccessfully
def change_channel(self, *args):
. Note theself
as first argument. And: no, you can't just remove allself
prefixes. You will get an error.change_channel
as a@staticmethod
, but in that case it won't be able to referenceself
within the method. If you want to referenceself
in the method then you have to declare it in the method declaration.