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

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:

主站蜘蛛池模板: 四平市| 共和县| 临沭县| 来安县| 衡山县| 苏尼特右旗| 甘德县| 青铜峡市| 巫溪县| 友谊县| 海盐县| 长汀县| 麻栗坡县| 磴口县| 双流县| 新干县| 句容市| 舞钢市| 拉孜县| 礼泉县| 奉化市| 崇礼县| 门源| 昭通市| 丁青县| 徐州市| 聂拉木县| 安陆市| 阳泉市| 永昌县| 华蓥市| 旌德县| 五河县| 古丈县| 和硕县| 桑植县| 高雄县| 赤水市| 龙口市| 贵德县| 庄河市|