用python tkinter写一个多条转的按钮窗口
时间: 2023-05-13 14:06:09 浏览: 138
tkinter (1).pdf
好的,以下是一个简单的 Python Tkinter 多条转按钮窗口的代码:
```python
import tkinter as tk
class MultiSpinbox(tk.Frame):
def __init__(self, master, labels, values):
super().__init__(master)
self.labels = labels
self.spinbox_vars = []
self.spinbox_widgets = []
for i, label in enumerate(labels):
tk.Label(self, text=label).grid(row=i, column=0)
var = tk.StringVar(value=values[i])
self.spinbox_vars.append(var)
widget = tk.Spinbox(self, from_=0, to=100, textvariable=var)
widget.grid(row=i, column=1)
self.spinbox_widgets.append(widget)
def get_values(self):
return [var.get() for var in self.spinbox_vars]
class MultiSpinboxWindow(tk.Tk):
def __init__(self, labels, values):
super().__init__()
self.title("MultiSpinbox Window")
self.geometry("300x200")
self.multi_spinbox = MultiSpinbox(self, labels, values)
self.multi_spinbox.pack(pady=10)
tk.Button(self, text="OK", command=self.ok).pack(pady=10)
def ok(self):
values = self.multi_spinbox.get_values()
print("Values:", values)
if __name__ == "__main__":
labels = ["Label 1", "Label 2", "Label 3"]
values = ["10", "20", "30"]
window = MultiSpinboxWindow(labels, values)
window.mainloop()
```
这个程序创建了一个带有多个 Spinbox 的窗口,每个 Spinbox 都有一个标签。用户可以通过 Spinbox 来选择一个值,然后单击“OK”按钮以获取所有 Spinbox 的值。
阅读全文