用python写一个ttk.Treeview里放入一个class Ui_MainWindow(object):得代码
时间: 2024-05-08 13:19:54 浏览: 154
好的,这是用Python写一个ttk.Treeview里放入一个class Ui_MainWindow(object)的示例代码:
```python
import tkinter as tk
from tkinter import ttk
class Ui_MainWindow(object):
def __init__(self):
self.window = tk.Tk()
self.tree = ttk.Treeview(self.window)
self.tree.pack()
self.tree['columns'] = ('name', 'age', 'gender')
self.tree.column('#0', width=0, stretch=tk.NO)
self.tree.column('name', anchor=tk.CENTER, width=100)
self.tree.column('age', anchor=tk.CENTER, width=100)
self.tree.column('gender', anchor=tk.CENTER, width=100)
self.tree.heading('#0', text='', anchor=tk.CENTER)
self.tree.heading('name', text='Name', anchor=tk.CENTER)
self.tree.heading('age', text='Age', anchor=tk.CENTER)
self.tree.heading('gender', text='Gender', anchor=tk.CENTER)
self.tree.insert('', 'end', text='1', values=('Tom', '18', 'Male'))
self.tree.insert('', 'end', text='2', values=('Jerry', '20', 'Female'))
self.tree.insert('', 'end', text='3', values=('Jack', '22', 'Male'))
if __name__ == '__main__':
ui = Ui_MainWindow()
ui.window.mainloop()
```
希望能够解决您的问题!
阅读全文