[Python] pyhton TTKBootstrap Menu - style not applied

Discussão em 'Python' iniciado por Stack, Abril 27, 2025.

  1. Stack

    Stack Membro Participativo

    I tried TTKBootstrap instead of tkinter and it looks great. However the menu has not been adapted.

    I do the following: Create a Windows based on tb.Window

    import ttkbootstrap as tb
    class App(tb.Window):
    def __init__(self):
    super().__init__()

    # configure the root window
    self.title('test ttkbootstrap')
    self.geometry('800x600')
    style = tb.Style(theme='superhero')


    and create a menu in the class constructor

    menubar = tb.Menu(self)
    self.config(menu=menubar)
    # file Menu
    filemenu = tb.Menu(menubar, tearoff=False)
    filemenu.add_command(
    label="Open...",
    command=OpenFile
    )


    It works, but looks like the style is not applied.

    [​IMG]

    Here the full code:

    from tkinter import filedialog
    import ttkbootstrap as tb

    def OpenFile():
    filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
    print(filename)

    def About():
    print("This is a simple example of a menu")

    class App(tb.Window):
    def __init__(self):
    super().__init__()

    # configure the root window
    self.title('test ttkbootstrap')
    self.geometry('800x600')
    style = tb.Style(theme='superhero')

    self.tabList = []

    # tabular Widgets
    tabControl = tb.Notebook(self, style='lefttab.TNotebook')
    tabControl.pack(pady=20)
    self.tabList.append(tb.Frame(tabControl))
    tabControl.add(self.tabList[-1], text ='First Tab')

    self.tabList.append(tb.Frame(tabControl))
    tabControl.add(self.tabList[-1], text ='Second Tab')

    tabControl.pack(expand=1, fill="both")

    # label
    self.label = tb.Label(self.tabList[0], text='Hello, First Tab!')
    self.label.pack()

    # button
    self.button = tb.Button(self.tabList[1], text='Click Me')
    self.button.pack()

    # Initialize and define the menu including functions to be called.

    menubar = tb.Menu(self)
    self.config(menu=menubar)
    # file Menu
    filemenu = tb.Menu(menubar, tearoff=False)
    filemenu.add_command(
    label="Open...",
    command=OpenFile
    )
    filemenu.add_separator()
    filemenu.add_command(
    label='Exit',
    command=self.destroy,
    )
    menubar.add_cascade(
    label="File",
    menu=filemenu,
    underline=0
    )
    # help Menu
    helpmenu = tb.Menu(menubar, tearoff=False)
    helpmenu.add_command(label="About...", command=About)
    menubar.add_cascade(label="Help", menu=helpmenu)

    if __name__ == "__main__":
    app = App()
    app.mainloop()

    Continue reading...

Compartilhe esta Página