各位前輩,請教一件事情,以下是我寫的一個小程式,這是要了解為什麼label 資料只顯示至 label 816,最後面的資料會一直覆蓋直至顯示label 1190
import tkinter as tk
def on_configure(event):
canvas.configure(scrollregion=canvas.bbox('all'))
def query_all_agr():
# 示範查詢資料的功能
agr_records = [f'資料 {i+1}' for i in range(1190)]
display_agr_data(agr_records)
def display_agr_data(agr_records):
for widget in inner_frame.winfo_children():
widget.destroy()
for i, record in enumerate(agr_records):
label = tk.Label(inner_frame, text=record, font=('Arial', 16))
label.grid(row=i, column=0, sticky='w', padx=5, pady=5)
inner_frame.update_idletasks()
canvas.configure(scrollregion=canvas.bbox('all'))
root = tk.Tk()
root.title('資料庫查詢系統')
root.geometry('1400x1400')
agr_frame = tk.Frame(root)
agr_frame.grid(row=0, column=0, sticky='nsew')
agr_frame.pack_propagate(False)
upper_frame3 = tk.Frame(agr_frame, width=400, height=100, bg='lightblue')
upper_frame3.grid(row=0, column=0, sticky='nsew', padx=5, pady=5)
upper_frame3.pack_propagate(False)
upper_frame4 = tk.Frame(agr_frame, width=500, height=100, bg='lightgreen')
upper_frame4.grid(row=0, column=1, sticky='nsew', padx=5, pady=5)
upper_frame4.pack_propagate(False)
upper_frame5 = tk.Frame(agr_frame, width=500, height=100, bg='lightyellow')
upper_frame5.grid(row=0, column=2, sticky='nsew', padx=5, pady=5)
upper_frame5.pack_propagate(False)
lower_frame1 = tk.Frame(agr_frame, width=1400, height=1000)
lower_frame1.grid(row=1, column=0, columnspan=3, sticky='nsew')
lower_frame1.pack_propagate(False)
agr_frame.grid_rowconfigure(0, weight=1)
agr_frame.grid_rowconfigure(1, weight=1)
agr_frame.grid_columnconfigure(0, weight=1)
agr_frame.grid_columnconfigure(1, weight=1)
agr_frame.grid_columnconfigure(2, weight=1)
canvas = tk.Canvas(lower_frame1, width=1400, height=1200)
canvas.grid(row=0, column=0, sticky='nsew')
scrollbar_y = tk.Scrollbar(lower_frame1, orient='vertical', command=canvas.yview)
scrollbar_y.grid(row=0, column=1, sticky='ns')
scrollbar_x = tk.Scrollbar(lower_frame1, orient='horizontal', command=canvas.xview)
scrollbar_x.grid(row=1, column=0, sticky='ew')
canvas.configure(yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set)
inner_frame = tk.Frame(canvas)
canvas.create_window((0, 0), window=inner_frame, anchor='nw')
inner_frame.bind('', on_configure)
query_button1 = tk.Button(upper_frame3, text='查詢所有資料', font=('Arial', 16), command=query_all_agr)
query_button1.pack(padx=5, pady=5)
query_button2 = tk.Button(upper_frame4, text='查詢所有資料', font=('Arial', 16), command=query_all_agr)
query_button2.pack(padx=5, pady=5)
query_button3 = tk.Button(upper_frame5, text='查詢所有資料', font=('Arial', 16), command=query_all_agr)
query_button3.pack(padx=5, pady=5)
root.mainloop()