| 123456789101112131415161718192021222324252627282930313233 |
- #使用python构建一个UI页面 上面有3个按钮
- #点击按钮1,弹出toast提示“点击了按钮1”
- #点击按钮2,弹出toast提示“点击了按钮2”
- #点击按钮3,弹出toast提示“点击了按钮3”
- import tkinter as tk
- from tkinter import messagebox
- class ToastApp:
- def __init__(self):
- self.root = tk.Tk()
- self.root.title("Button Demo")
- self.root.geometry("300x200")
- # Create and pack buttons
- for i in range(3):
- btn = tk.Button(
- self.root,
- text=f"Button {i + 1}",
- command=lambda x=i + 1: self.show_toast(x)
- )
- btn.pack(pady=10)
- def show_toast(self, button_num):
- messagebox.showinfo("Toast", f"Clicked Button {button_num}")
- def run(self):
- self.root.mainloop()
- if __name__ == "__main__":
- app = ToastApp()
- app.run()
|