代码之家  ›  专栏  ›  技术社区  ›  Pixl

如何制作彩色纽扣

  •  0
  • Pixl  · 技术社区  · 2 年前

    我是python和Tkinter的初学者,我想让自定义按钮看起来更好。如何让Tkinter按钮利用python中的自定义背景和文本颜色?

    1 回复  |  直到 2 年前
        1
  •  0
  •   Ron Vermann    2 年前

    用Tkinter制作彩色按钮并不难,只需在定义按钮时添加一些参数即可。

    from tkinter import *
    
    # Define the Window
    root = Tk()
    # Add a Title to The Window
    root.title('Colored Button')
    # Geometry of window; width by length in pixels
    root.geometry('300x200')
    # Define the Button; fg is the foreground, bg is the background.
    colored_button = Button(root, fg='White', bg='Black', text = 'Click Me')
    # Pack the Button
    colored_button.pack()
    # Run the TKinter loop
    root.mainloop()