0

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:

enter image description here

asked Oct 30, 2023 at 11:02
4
  • 1
    Style may not be applied to all themes, so try switching to other theme. Commented Oct 30, 2023 at 11:40
  • 1
    @RichardL. Are you running on macos? It worked on Windows 10. Commented Oct 30, 2023 at 11:51
  • @toyotaSupra I‘m on macOS (13.4.1) Commented Oct 31, 2023 at 12:07
  • Does this answer your question? Simple Tkinter python Programm doesn't work Commented Oct 31, 2023 at 12:19

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.