How do I change the background of a Frame in Tkinter?

后端 未结 2 1678
你的背包
你的背包 2020-11-30 13:40

I have been creating an Email program using Tkinter, in Python 3.3. On various sites I have been seeing that the Frame widget can get a different background using <

2条回答
  •  旧巷少年郎
    2020-11-30 13:57

    You use ttk.Frame, bg option does not work for it. You should create style and apply it to the frame.

    from tkinter import *
    from tkinter.ttk import * 
    
    root = Tk()
    
    s = Style()
    s.configure('My.TFrame', background='red')
    
    mail1 = Frame(root, style='My.TFrame')
    mail1.place(height=70, width=400, x=83, y=109)
    mail1.config()
    root.mainloop()
    

提交回复
热议问题