- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 121字
- 2021-08-27 19:44:00
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:

推薦閱讀
- R語言數據分析從入門到精通
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- SQL語言從入門到精通
- 深入分布式緩存:從原理到實踐
- Go語言精進之路:從新手到高手的編程思想、方法和技巧(1)
- Scala Reactive Programming
- UNIX Linux程序設計教程
- IDA Pro權威指南(第2版)
- App Inventor少兒趣味編程動手做
- Mudbox 2013 Cookbook
- Python應用與實戰
- 體驗之道:從需求到實踐的用戶體驗實戰
- Practical Time Series Analysis
- 歐姆龍PLC編程指令與梯形圖快速入門
- A/B 測試:創新始于試驗