|
发表于 2021-2-4 22:16:06
|
显示全部楼层
稀里糊涂弄出来了
给 configure 第一个参数 和 Button 的 style 参数进行对应即可:
- import tkinter as tk
- import tkinter.ttk as ttk
- class Button_ttk:
- def __init__(self, root):
- self.root = root
- ttk.Style().configure('First.TButton', relief="flat", foreground='red')
- btn = ttk.Button(self.root, text='xxx', style='First.TButton', command=self.fun_with_args(0))
- btn.grid()
- ttk.Style().configure('Second.TButton', relief="sunken", foreground='blue')
- btn1 = ttk.Button(self.root, text='xxx', style='Second.TButton', command=self.fun_with_args(0))
- btn1.grid()
- def fun_with_args(self, x):
- print('------------------------')
- if __name__ == '__main__':
- root = tk.Tk()
- Button_ttk(root)
- tk.mainloop()
复制代码 |
|