Replies: 2 comments
-
Hello @kikigeo, thanks for trying pygubu.
Maybe just add another submenu ? Here is an example. exportmenu.ui <?xml version='1.0' encoding='utf-8'?>
<interface version="1.3">
<object class="tk.Toplevel" id="toplevel1">
<property name="geometry">320x200</property>
<property name="height">200</property>
<property name="title" translatable="yes">Menu test</property>
<property name="width">200</property>
<child>
<object class="pygubu.builder.widgets.toplevelmenu" id="toplevelmenu1">
<child>
<object class="tk.Menu" id="main_menu" named="True">
<property name="tearoff">false</property>
<child>
<object class="tk.Menuitem.Submenu" id="submenu1">
<property name="label" translatable="yes">File</property>
<property name="tearoff">false</property>
<child>
<object class="tk.Menuitem.Submenu" id="submenu2">
<property name="label" translatable="yes">Export to …</property>
<property name="tearoff">false</property>
<child>
<object class="tk.Menuitem.Command" id="export_pdf" named="True">
<property name="command" type="command" cbtype="with_wid">export_menuitem_clicked</property>
<property name="label" translatable="yes">PDF</property>
</object>
</child>
<child>
<object class="tk.Menuitem.Command" id="export_doc" named="True">
<property name="command" type="command" cbtype="with_wid">export_menuitem_clicked</property>
<property name="label" translatable="yes">DOCX</property>
</object>
</child>
<child>
<object class="tk.Menuitem.Command" id="export_xls" named="True">
<property name="command" type="command" cbtype="with_wid">export_menuitem_clicked</property>
<property name="label" translatable="yes">XLSX</property>
</object>
</child>
</object>
</child>
<child>
<object class="tk.Menuitem.Separator" id="separator1" />
</child>
<child>
<object class="tk.Menuitem.Command" id="command1">
<property name="command" type="command" cbtype="simple">on_quit_clicked</property>
<property name="label" translatable="yes">Quit</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
exportmenuapp.py #!/usr/bin/python3
import pathlib
import tkinter as tk
import tkinter.messagebox as messagebox
import pygubu
PROJECT_PATH = pathlib.Path(__file__).parent
PROJECT_UI = PROJECT_PATH / "exportmenu.ui"
class ExportmenuApp:
def __init__(self, master=None):
self.builder = builder = pygubu.Builder()
builder.add_resource_path(PROJECT_PATH)
builder.add_from_file(PROJECT_UI)
# Main widget
self.mainwindow: tk.Toplevel = builder.get_object("toplevel1", master)
builder.connect_callbacks(self)
def run(self):
self.mainwindow.mainloop()
def export_menuitem_clicked(self, itemid):
msg = f"You clicked {itemid}"
dlg_options = {"parent": self.mainwindow}
messagebox.showinfo("My App", msg, **dlg_options)
def on_quit_clicked(self):
self.mainwindow.quit()
if __name__ == "__main__":
app = ExportmenuApp()
app.run() Or maybe you want to create the options dynamically? Let me know. Regards |
Beta Was this translation helpful? Give feedback.
0 replies
-
Dear Alejandro,
I want to thank you for your reply! I didn't know that the menu designer
could be arranged in the way you showed me in the example. I even tried it
last night, but it didn't seem to allow me (some kind of bug).
Thank you very much again! You helped me a lot!
Warm regards,
Polić Kristian
sub, 2. ožu 2024. u 04:56 Alejandro Autalán ***@***.***>
napisao je:
… Hello @kikigeo <https://github.com/kikigeo>, thanks for trying pygubu.
I just wanted to ask you how to expand the "command" item in "submenu"
using Pygubu designer? For instance: under the submenu "file" i have
command "export" and I want it to expand into "PDF", "DOCX" and "XLSX".
Thank you in advance!
Maybe just add another submenu ? Here is an example.
exportmenu.ui
<?xml version='1.0' encoding='utf-8'?>
<interface version="1.3">
<object class="tk.Toplevel" id="toplevel1">
<property name="geometry">320x200</property>
<property name="height">200</property>
<property name="title" translatable="yes">Menu test</property>
<property name="width">200</property>
<child>
<object class="pygubu.builder.widgets.toplevelmenu" id="toplevelmenu1">
<child>
<object class="tk.Menu" id="main_menu" named="True">
<property name="tearoff">false</property>
<child>
<object class="tk.Menuitem.Submenu" id="submenu1">
<property name="label" translatable="yes">File</property>
<property name="tearoff">false</property>
<child>
<object class="tk.Menuitem.Submenu" id="submenu2">
<property name="label" translatable="yes">Export to …</property>
<property name="tearoff">false</property>
<child>
<object class="tk.Menuitem.Command" id="export_pdf" named="True">
<property name="command" type="command" cbtype="with_wid">export_menuitem_clicked</property>
<property name="label" translatable="yes">PDF</property>
</object>
</child>
<child>
<object class="tk.Menuitem.Command" id="export_doc" named="True">
<property name="command" type="command" cbtype="with_wid">export_menuitem_clicked</property>
<property name="label" translatable="yes">DOCX</property>
</object>
</child>
<child>
<object class="tk.Menuitem.Command" id="export_xls" named="True">
<property name="command" type="command" cbtype="with_wid">export_menuitem_clicked</property>
<property name="label" translatable="yes">XLSX</property>
</object>
</child>
</object>
</child>
<child>
<object class="tk.Menuitem.Separator" id="separator1" />
</child>
<child>
<object class="tk.Menuitem.Command" id="command1">
<property name="command" type="command" cbtype="simple">on_quit_clicked</property>
<property name="label" translatable="yes">Quit</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
exportmenuapp.py
#!/usr/bin/python3import pathlibimport tkinter as tkimport tkinter.messagebox as messageboximport pygubu
PROJECT_PATH = pathlib.Path(__file__).parentPROJECT_UI = PROJECT_PATH / "exportmenu.ui"
class ExportmenuApp:
def __init__(self, master=None):
self.builder = builder = pygubu.Builder()
builder.add_resource_path(PROJECT_PATH)
builder.add_from_file(PROJECT_UI)
# Main widget
self.mainwindow: tk.Toplevel = builder.get_object("toplevel1", master)
builder.connect_callbacks(self)
def run(self):
self.mainwindow.mainloop()
def export_menuitem_clicked(self, itemid):
msg = f"You clicked {itemid}"
dlg_options = {"parent": self.mainwindow}
messagebox.showinfo("My App", msg, **dlg_options)
def on_quit_clicked(self):
self.mainwindow.quit()
if __name__ == "__main__":
app = ExportmenuApp()
app.run()
Or maybe you want to create the options dynamically? Let me know.
Regards
Alejandro A.
—
Reply to this email directly, view it on GitHub
<#239 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BEV4ZVDAUGSQRWFHTQYIZSLYWFEYVAVCNFSM6AAAAABECPB6Z2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DMNBZGYYTM>
.
You are receiving this because you were mentioned.Message ID:
<alejandroautalan/pygubu-designer/repo-discussions/239/comments/8649616@
github.com>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello people,
I just wanted to ask you how to expand the "command" item in "submenu" using Pygubu designer? For instance: under the submenu "file" i have command "export" and I want it to expand into "PDF", "DOCX" and "XLSX". Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions