Search code examples
pythontkinterttkbootstrap

The ttkbootstrap style is not working. How can I fix it?


The ttkbootstrap style is not working. The window looks like this.

enter image description here

The full code is here.

This is my code:

a.py:

from tkinter import filedialog
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from b import *

root = ttk.Window()

b1 = ttk.Button(root, text="Button 1", bootstyle=SUCCESS, command=test)
b1.pack(side=LEFT, padx=5, pady=10)

b2 = ttk.Button(root, text="Button 2", bootstyle=(INFO, OUTLINE))
b2.pack(side=LEFT, padx=5, pady=10)

root.mainloop()

b.py:

import ttkbootstrap as ttk
from ttkbootstrap.constants import *

def test():
    root = ttk.Window()

    b1 = ttk.Button(root, text="Button 1", bootstyle=SUCCESS)
    b1.pack(side=LEFT, padx=5, pady=10)

    root.mainloop()

When I call test() function in a.py, the window created by b.py looks strange. It's still the tkinter style.

How can I fix it? I don't like the tkinter style.


Solution

  • When I call test() function in a.py, the window created by b.py looks strange. It's still the tkinter style.

    How can I fix it? I don't like the tkinter style.

    The problem can be fixed.

    On b.py. Change this:

    root = ttk.Window()
    

    to:

    root = ttk.Toplevel()
    

    Use one mainloop() for entire modules.

    Snippet:

    import ttkbootstrap as ttk
    from ttkbootstrap.constants import *
    
    def test():
        root = ttk.Toplevel()
    
        b1 = ttk.Button(root, text="Button 3", bootstyle=SUCCESS)
        b1.pack(side=LEFT, padx=55, pady=10)
    
        #root.mainloop()
    

    Screenshot for a.py:

    enter image description here

    Screenshot for b.py: enter image description here