用python tkinter写一个多按钮系统
时间: 2023-05-13 09:06:11 浏览: 77
好的,以下是一个简单的 Python Tkinter 多按钮系统的示例代码:
```python
import tkinter as tk
class MultiButtonSystem:
def __init__(self, master):
self.master = master
self.master.title("多按钮系统")
# 创建按钮
self.button1 = tk.Button(self.master, text="按钮1", command=self.button1_clicked)
self.button2 = tk.Button(self.master, text="按钮2", command=self.button2_clicked)
self.button3 = tk.Button(self.master, text="按钮3", command=self.button3_clicked)
# 将按钮添加到窗口中
self.button1.pack()
self.button2.pack()
self.button3.pack()
def button1_clicked(self):
print("按钮1被点击了!")
def button2_clicked(self):
print("按钮2被点击了!")
def button3_clicked(self):
print("按钮3被点击了!")
root = tk.Tk()
app = MultiButtonSystem(root)
root.mainloop()
```
这个程序创建了一个窗口,其中包含三个按钮。每个按钮都有一个回调函数,当按钮被点击时,它们将打印一条消息到控制台。你可以根据需要修改这些回调函数,以便它们执行你想要的操作。