Background color for Tk in Python

后端 未结 5 1287
青春惊慌失措
青春惊慌失措 2020-12-25 09:40

I\'m writing a slideshow program with Tkinter, but I don\'t know how to change the background color to black instead of the standard light gray. How can this be done?

<
相关标签:
5条回答
  • 2020-12-25 10:16

    config is another option:

    widget1.config(bg='black')
    widget2.config(bg='#000000')
    

    or:

    widget1.config(background='black')
    widget2.config(background='#000000')
    
    0 讨论(0)
  • 2020-12-25 10:34
    widget['bg'] = '#000000'
    

    or

    widget['background'] = '#000000'
    

    would also work as hex-valued colors are also accepted.

    0 讨论(0)
  • 2020-12-25 10:35

    I know this is kinda an old question but:

    root["bg"] = "black"
    

    will also do what you want and it involves less typing.

    0 讨论(0)
  • 2020-12-25 10:41
    root.configure(background='black')
    

    or more generally

    <widget>.configure(background='black')
    
    0 讨论(0)
  • 2020-12-25 10:42

    Its been updated so

    root.configure(background="red")
    

    is now:

    root.configure(bg="red")
    
    0 讨论(0)
提交回复
热议问题