ich gehe gerade meine ersten Python schritte, noch mit sehr viel Hilfe der Lieben AI..
langsam aber sicher verstehe ich aber die ersten Züge der Sprache

zu meinem Problem:
ich habe jetzt mal das grobe Framework für eine kleine Anwendung erstellt:
- 3 Menüleisten (Oben, Unten und Seitlich)
- eine Dateneingabe
- und dann soll darüber noch ein Diagram auf basis der Daten hin kommen
soweit so gut, ist noch nicht schön, aber es ist da..
in der unteren Menüleiste habe ich einen Button zum Hinzufügen von Zeilen eingefügt, das funktioniert auch.
Leider kann ich mit der Scrollbar die Tabellenzeilen nicht scrollen..
ich denke es hat was mit dem canvas.itemconfig zu tun, aber das habe ich ursprünglich mal gebraucht, damit die Tabelle in der Position bleibt wo sie soll..
würd mich freun wenn mir da wer helfen könnte

hier der Gesamte Code:
Code: Alles auswählen
import tkinter as tk
root = tk.Tk()
root.title("Testprogram")
# Start the window maximized (this does not cover the taskbar)
root.state('zoomed')
row_count = 10
# Function to exit fullscreen or maximized state
def exit_fullscreen(event=None):
root.attributes('-fullscreen', False)
return "break"
def create_input_fields(parent, start_row, row_count, columns):
entries = []
for i in range(start_row, start_row + row_count):
row_entries = []
for j in range(columns):
entry = tk.Entry(parent)
entry.grid(row=i, column=j, sticky="nsew")
row_entries.append(entry)
entries.append(row_entries)
return entries
def add_new_row():
global row_count
new_row_entries = create_input_fields(inner_frame, row_count, 1, 12) # Add one new row
input_fields.extend(new_row_entries)
row_count += 1
# Update the scroll region to encompass the new row
update_scrollregion()
def update_scrollregion():
# Update the scroll region to encompass the new row
canvas.configure(scrollregion=canvas.bbox("all"))
def update_canvas_window_size(event):
canvas_width = event.width
canvas_height = event.height
canvas.itemconfig(canvas_window, width=canvas_width, height=canvas_height)
update_scrollregion()
# Bind escape key to exit fullscreen or maximized state
root.bind('<Escape>', exit_fullscreen)
# Create the main layout frames
header_frame = tk.Frame(root, borderwidth=2, relief="ridge", background="blue")
content_frame = tk.Frame(root, borderwidth=2, relief="ridge")
side_inputs_frame = tk.Frame(root, borderwidth=2, relief="ridge", background="orange")
bottom_menu_frame = tk.Frame(root, borderwidth=2, relief="ridge", background="teal")
# Layout the main frames using grid
header_frame.grid(row=0, column=0, columnspan=2, sticky="nsew")
content_frame.grid(row=1, column=0, sticky="nsew")
side_inputs_frame.grid(row=1, column=1, sticky="nsew")
bottom_menu_frame.grid(row=2, column=0, columnspan=2, sticky="nsew") # Fixed grid placement here
# Configure weights to make frames resizable
root.grid_rowconfigure(0, weight=1) # Header area
root.grid_rowconfigure(1, weight=30) # Content area, larger weight to give more space
root.grid_rowconfigure(2, weight=1) # Bottom menu area
root.grid_columnconfigure(0, weight=5) # Main content area is larger
root.grid_columnconfigure(1, weight=1) # Side inputs area is smaller
# Create nested frames within the content frame for diagram and table
diagram_frame = tk.Frame(content_frame, borderwidth=2, relief="ridge", background="orange")
Htable_frame = tk.Frame(content_frame, borderwidth=2, relief="ridge", background="green")
table_frame = tk.Frame(content_frame, borderwidth=2, relief="ridge", background="yellow")
# Layout the nested frames using grid within the content frame
diagram_frame.grid(row=0, column=0, sticky="nsew")
Htable_frame.grid(row=1, column=0, sticky="nsew")
table_frame.grid(row=2, column=0, sticky="nsew")
# Configure weights to make nested frames resizable
content_frame.grid_rowconfigure(0, weight=80) # Diagram area
content_frame.grid_rowconfigure(1, weight=2) # column header
content_frame.grid_rowconfigure(2, weight=30) # Table area
content_frame.grid_columnconfigure(0, weight=1)
# Create a Canvas and a Scrollbar within table_frame
canvas = tk.Canvas(table_frame)
scrollbar = tk.Scrollbar(table_frame, orient="vertical", command=canvas.yview)
# Grid and pack the widgets
canvas.grid(row=0, column=0, sticky="nsew")
scrollbar.grid(row=0, column=1, sticky="ns")
# Configure the canvas to work with the scrollbar
canvas.configure(yscrollcommand=scrollbar.set)
# Configure the table_frame to accommodate the canvas and scrollbar
table_frame.grid_columnconfigure(0, weight=1) # Canvas should expand to fill the frame
table_frame.grid_rowconfigure(0, weight=1)
# Create a frame inside the canvas to hold the input fields
inner_frame = tk.Frame(canvas)
canvas_window = canvas.create_window((0, 0), window=inner_frame, anchor='nw')
# Bind the function to the table_frame's configure event
table_frame.bind("<Configure>", update_canvas_window_size)
# Add headers to Htable_frame
headers = ["Header {}".format(i+1) for i in range(12)]
for idx, header in enumerate(headers):
label = tk.Label(Htable_frame, text=header, bg='green', fg='white')
label.grid(row=0, column=idx, sticky="nsew")
Htable_frame.grid_columnconfigure(idx, weight=1, uniform='header')
# Add input fields to inner_frame instead of table_frame
input_fields = create_input_fields(inner_frame, 0, row_count, 12) # 10 rows of input fields
# Ensure the input fields align with the headers
for j in range(12):
inner_frame.grid_columnconfigure(j, weight=1, uniform='header')
# Update the canvas's scrollregion whenever the inner_frame's size changes
inner_frame.bind("<Configure>", lambda event: canvas.configure(scrollregion=canvas.bbox("all")))
add_row_button = tk.Button(bottom_menu_frame,text="Neue Zeile", command=add_new_row)
add_row_button.grid(row=0, column=idx, sticky="nsew")
root.mainloop()