iT邦幫忙

1

標籤資料無法完整的顯示

  • 分享至 

  • xImage

各位前輩,請教一件事情,以下是我寫的一個小程式,這是要了解為什麼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 和滾動條

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()

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答