Ich weiss wirklich nicht mehr weiter und die Beispiele im Internet halfen nicht.
Könnt ihr bitte helfen?
Code: Alles auswählen
class Table(ttk.Treeview):
def __init__(self, master, data):
super().__init__(master)
yscrollbar = ttk.Scrollbar(master, orient="vertical", command=self.yview)
yscrollbar.grid(row=0, column=2, sticky="NS")
self.configure(yscrollcommand=yscrollbar.set)
xscrollbar = ttk.Scrollbar(master, orient="horizontal", command=self.xview)
xscrollbar.grid(row=1, column=1, sticky="EW")
self.configure(xscrollcommand=xscrollbar.set)
self.headers = data[0]
self.sizes = [int(size) for size in data[1]]
data = data[2:]
column_names = tuple([str(number) for number in range(len(self.headers))])
self["columns"] = column_names
self["show"] = "headings"
for header, size, name in zip(self.headers, self.sizes, column_names):
self.column(name, width=int(size), minwidth=int(size), anchor="w")
self.heading(name, text=header, anchor="w")
for i, column in enumerate(data):
self.insert("", i, text="", values=tuple(column))
self.bind("<Double-1>", self.on_double_click)
def insert_column(self, entries):
data = [entry.get() for entry in entries]
self.insert("", randrange(1000, 10000000), text="", values=tuple(data))
def get_data(self):
data = []
data.append(self.headers)
data.append(self.sizes)
for child in self.get_children():
data.append(self.item(child)["values"])
return data
def on_double_click(self, event):
region = self.identify("region", event.x, event.y)
if region == "heading":
pass
else:
warning = Warning(title="Bestätigung", message=self.item(event.widget.focus())['values'])
if warning.value:
self.delete(event.widget.focus())