python 设置按钮的边框样式(图文)

发布时间:2020-12-15编辑:脚本学堂
本文分享一例python代码,学习如何设置按钮的边框样式,有需要的朋友参考下吧。

python 设置按钮的边框样式,代码如下:

#!/bin/python
from Tkinter import *

class GUI:
    def __init__(self):
     self.root = Tk()
        self.root.title('Button Styles')
        for bdw in range(5):
            setattr(self, 'of%d' % bdw, Frame(self.root, borderwidth=0))
            Label(getattr(self, 'of%d' % bdw),
                  text='borderwidth = %d  ' % bdw).pack(side=LEFT)
            for relief in [RAISED, SUNKEN, FLAT, RIDGE, GROOVE, SOLID]:
                Button(getattr(self, 'of%d' % bdw), text=relief, borderwidth=bdw,
                       relief=relief, width=10,
                       command=lambda s=self, r=relief, b=bdw: s.prt(r,b))
                          .pack(side=LEFT, padx=7-bdw, pady=7-bdw)
            getattr(self, 'of%d' % bdw).pack()

    def prt(self, relief, border):
        print '%s:%d' % (relief, border)

myGUI = GUI()
myGUI.root.mainloop()

效果图:
python按钮边框样式