I am trying to write code for a very simple frame layout in tkinter/ tkk to understand how it works and I am running into a problem, where I can't find awnsers online. I am trying to color a frame using the style configure method. I am able to create a new 'TFrame' style object. However, when I set the defined style for a frame it is not applied (see image). The code doesn't through any errors, it just doesn't apply the style. What am I doing wrong? Is this because of my interpreter? I am using Python 3.10.2
This my code:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title('style Test')
root.geometry('400x300')
style = ttk.Style()
style.configure('new.TFrame', background='green')
style.configure('new.TButton', font=('Myriad Pro', 20), background='red')
mainFrame = ttk.Frame(root, width=200, height=200, style='new.TFrame')
mainFrame.grid()
button = ttk.Button(root, text='Some text' ,style='new.TButton')
button.grid()
root.mainloop()
This my output window:
-
1Style may not be applied to all themes, so try switching to other theme.acw1668– acw16682023年10月30日 11:40:18 +00:00Commented Oct 30, 2023 at 11:40
-
1@RichardL. Are you running on macos? It worked on Windows 10.user4136999– user41369992023年10月30日 11:51:43 +00:00Commented Oct 30, 2023 at 11:51
-
@toyotaSupra I‘m on macOS (13.4.1)RichardL– RichardL2023年10月31日 12:07:18 +00:00Commented Oct 31, 2023 at 12:07
-
Does this answer your question? Simple Tkinter python Programm doesn't workuser4136999– user41369992023年10月31日 12:19:20 +00:00Commented Oct 31, 2023 at 12:19
lang-py