官术网_书友最值得收藏!

How to do it...

The following contains a button with an image that gets disabled when clicked and a list of buttons with the different types of available reliefs:

import tkinter as tk 
 
RELIEFS = [tk.SUNKEN, tk.RAISED, tk.GROOVE, tk.RIDGE, tk.FLAT] 
 
class ButtonsApp(tk.Tk): 
    def __init__(self): 
        super().__init__() 
        self.img = tk.PhotoImage(file="python.gif") 
        self.btn = tk.Button(self, text="Button with image", 
                             image=self.img, compound=tk.LEFT, 
                             command=self.disable_btn) 
        self.btns = [self.create_btn(r) for r in RELIEFS]         
        self.btn.pack() 
        for btn in self.btns: 
            btn.pack(padx=10, pady=10, side=tk.LEFT) 
 
    def create_btn(self, relief): 
        return tk.Button(self, text=relief, relief=relief) 
 
    def disable_btn(self): 
        self.btn.config(state=tk.DISABLED) 
 
if __name__ == "__main__": 
    app = ButtonsApp() 
    app.mainloop()

The purpose of this program is to show several configuration options that can be used when creating a Button widget.

After executing the preceding code, you will get the following output:

主站蜘蛛池模板: 渝中区| 阿巴嘎旗| 江陵县| 五原县| 德兴市| 江门市| 廉江市| 万年县| 宁河县| 黔东| 澄城县| 叙永县| 从江县| 射洪县| 五大连池市| 高密市| 云和县| 遵化市| 安塞县| 济宁市| 榆树市| 南涧| 宝兴县| 乐平市| 武功县| 五台县| 德庆县| 巴塘县| 石景山区| 天柱县| 馆陶县| 惠安县| 北流市| 丰原市| 锦州市| 惠来县| 来宾市| 永昌县| 阜城县| 武鸣县| 涟源市|