Python GUI Development with GTK+ 3 - Tutorial 4 - Boxes

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Interesting... :)

def button_clicked(self, widget):
print("You clicked ", widget.get_label())
>>> ('You clicked ', 'Bacon')

def button_clicked(self, widget):
print("You clicked " + widget.get_label())
>>> You clicked Bacon

kneekoo
Автор

I just came to say that I won in my mind

memoriasIT
Автор

I just make a class of button inside the initialize function of MainWindow.

class Button_In_Here(Gtk.Button):
def __init__(self, label_of_button):
Gtk.Button.__init__(self, label = label_of_button)
self.label = label_of_button
self.connect ("clicked", self.clicked)
def clicked (self, widget):
print ("You chose "+ self.label +"!")

#Yes button
self.yes_button = Button_In_Here("Yes")
self.box.pack_start(self.yes_button, True, True, 0)

#No
self.no_button = Button_In_Here("No")
self.box.pack_start(self.no_button, True, True, 0)

fatihnri
Автор

Thx for all this tips ! the "homework" to do is very interesting, but, if i imagine 2 different buttons totaly identical in appearence with no label (or the same label), is there a way to do something equivalent without creating a custom button class ?
I think of somtheing like an invisible propertie "reference" (wich does not exist...)

emailvinz
Автор

I prefer the way you don't need to use the objects!

higiniofuentes
Автор

def clicked(self, widget):
print("You click the " + + " button.")

TonyFreeman
Автор

I wish you'd explain more about why you use those "__init__(self..)"
I don't understand why I must refer to self all the time...

sebastianw.
Автор

hey bro >> where can i find the answer of homework of this lesson ?

medhatmoussa
Автор

Solution for the homework problem? Anyone?

nuthalapativarun