Apr-04-2018, 04:28 PM
Hi kellykimble
The purpose of a listbox widget is to display a set of lines of text not Widgets. But you would like to display a pair of Labels per line representing colors. For this you can't use the listbox-widget. One way is to put a frame containing all color labels in a canvas. Then it is possible to scroll the frame in the canvas. Look at the following skript:
The purpose of a listbox widget is to display a set of lines of text not Widgets. But you would like to display a pair of Labels per line representing colors. For this you can't use the listbox-widget. One way is to put a frame containing all color labels in a canvas. Then it is possible to scroll the frame in the canvas. Look at the following skript:
from tkinter import * def canvas_update(event): canvas = event.widget canvas.config(scrollregion=canvas.bbox('all')) def main () : window = Tk() window.title("Colors") #screen_width = window.winfo_screenwidth() #screen_height = window.winfo_screenheight() #window.geometry(str(screen_width)+"x"+str(screen_height)) main_frame = Frame(window, relief='groove', bd=2) main_frame.pack(expand=True, anchor='nw', padx=10, pady=10) canvas = Canvas(main_frame, width=200, height=400, highlightthickness=0) canvas.pack(side='left', expand=True) canvas.bind('<Configure>', canvas_update) scrollbar = Scrollbar(main_frame, orient="vertical") scrollbar.pack(side='left', fill='y') canvas.config(yscrollcommand=scrollbar.set) scrollbar.config(command=canvas.yview) color_frame = Frame(canvas) canvas.create_window(0, 0, anchor='nw', window=color_frame) #myframe.grid_propagate(0) # Simulate the color ranges: r1 = 250 g1 = 0 b1 = 0 r2 = 0 g2 = 0 b2 = 0 for ii in range(25): r1 -= 10 g1 += 5 mycolor = '#%02x%02x%02x' % (r1, g1, b1) mycolor2 = '#%02x%02x%02x' % (b2, g2, r2) list_frame = Frame(color_frame, relief='sunken') list_frame.pack(fill='x') Label(list_frame, text=str(ii), bg=mycolor, fg='black', width=12, height=4).pack(side='left') Label(list_frame, text=str(ii), bg=mycolor2, fg='black', width=12, height=4).pack(side='left') window.mainloop() if __name__ == '__main__': main()Greetings wuf