Closed wiryonolau closed 1 month ago
Hello @wiryonolau, thanks for trying pygubu.
You need to call _connectcallbacks after the main widget is created.
import os
from pygubu import Builder
class MainWindow:
def __init__(self, master = None):
ui_file = os.path.abspath("./issue295.ui")
self._builder = Builder()
self._builder.add_from_file(ui_file)
self._mainwindow = self._builder.get_object("mainwindow", master=master)
#
# Call setup handlers after main window is created.
#
self._setup_handlers()
def _setup_handlers(self):
self._builder.connect_callbacks(self)
def on_button_clicked(self):
print("working")
def run(self):
self._mainwindow.mainloop()
if __name__ == "__main__":
main = MainWindow()
main.run()
Let me know if you have more questions. Regards
Alejandro A.
Hello @wiryonolau, thanks for trying pygubu.
You need to call _connectcallbacks after the main widget is created.
import os from pygubu import Builder class MainWindow: def __init__(self, master = None): ui_file = os.path.abspath("./issue295.ui") self._builder = Builder() self._builder.add_from_file(ui_file) self._mainwindow = self._builder.get_object("mainwindow", master=master) # # Call setup handlers after main window is created. # self._setup_handlers() def _setup_handlers(self): self._builder.connect_callbacks(self) def on_button_clicked(self): print("working") def run(self): self._mainwindow.mainloop() if __name__ == "__main__": main = MainWindow() main.run()
Let me know if you have more questions. Regards
Alejandro A.
Thanks I just found out too. It just for mainwindow or other get_object also required to be called before connect_callbacks ?
The call to connect_callbacks searches among the created widgets and connects the callbacks.
Example, if you have one toplevel widget:
mainwindow
> button 1
> button 2
> frame a
> checkbutton
> button 5
Just get the main window and then connect the commmands.
...
self.builder.get_object("mainwindow", master=master)
...
self.builder.connect_commands(self)
...
Another example, a main window with a large menu definition (defined outside the mainwindow tree in the same ui file) .
mainwindow: Toplevel
> button 1
> button 2
mainmenu: Menu
> File
> More menu options with commands
> Quit
> Other submenu
...
Create the main window, the menu, an then connect commands.
...
mainwindow = self.builder.get_object("mainwindow", master=master)
menu = self.builder.get_object("mainmenu", mainwindow)
mainwindow.configure(menu=menu)
...
self.builder.connect_commands(self)
...
Regards Alejandro A.
ok thanks.
Describe the bug connect_callbacks doing nothing, self.objects.items() always empty window and widget is displayed with no error
To Reproduce
Expected behavior when button in click , it print output
Screenshots None
Your Environment (please complete the following information):
Additional context Button do nothing, when check on the connect_callbacks function, self.objects always empty