Apr-04-2018, 11:59 AM
I am trying to use a Listbox to display and scroll through a saved list of "color ranges" but I cannot get the sizing and scrolling to cooperate.
This is my first attempt at using tKinter, and I am fairly new to Python as well so its been quite frustrating.
I expect it is something simple I am missing, but I have tried every solution I could Google.
Either the Scrollbar will not scroll the list, or the list grows out of its frame or grid box.
Any help would be appreciated.
This is my first attempt at using tKinter, and I am fairly new to Python as well so its been quite frustrating.
I expect it is something simple I am missing, but I have tried every solution I could Google.
Either the Scrollbar will not scroll the list, or the list grows out of its frame or grid box.
Any help would be appreciated.
from tkinter import * import os import sys def main () : window = Tk() # create window window.title("Colors") screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight() window.geometry(str(screen_width)+"x"+str(screen_height)) window.resizable(0, 0) #Don't allow resizing in the x or y direction lbl2 = Label(window, text="HELLO", fg='black', font=("Helvetica", 16,"bold")) lbl2.pack() window.update() fontwidth = lbl2.winfo_width() fontheight = lbl2.winfo_height() frameWidth = screen_width * .15 lbl2.destroy() myframe=Frame(window,width=frameWidth+20, height = fontheight * 12) myframe.grid() myframe.grid_propagate(0) scrollbar = Scrollbar(orient="vertical") listSelection = Listbox(myframe, width=int(frameWidth*.95), height=4) listSelection.grid(row=0, column=0,sticky=N+S+W) #listSelection.grid_propagate(0) listSelection.yscrollcommand = scrollbar.set scrollbar.command = listSelection.yview scrollbar.grid(row=0, column=1,sticky=N+S+E) scrollbar.grid_propagate(0) listSelection.yview_scroll(1,"units") listSelection.yview_scroll(1,"units") # Simulate the color ranges: r1 = 250 g1 = 0 b1 = 0 r2 = 0 g2 = 0 b2 = 0 for ii in range(0,25): r1 -= 10 g1 += 5 mycolor = '#%02x%02x%02x' % (r1, g1, b1) # set your favourite rgb color mycolor2 = '#%02x%02x%02x' % (b2, g2, r2) # set your favourite rgb color frameWidth2 = int(frameWidth * .25) f = Frame(listSelection,width=frameWidth, height = fontheight * 2, relief=SUNKEN) f.grid() f.grid_propagate(0) a=Label(f, text=" " + str(ii) + " ", bg=mycolor, fg='black',width=12) b=Label(f, text=" " + str(ii) + " ", bg=mycolor2, fg='black',width=12,height = 4) a.grid(row = 0, column = 0, sticky=N+S) b.grid(row = 0, column = 1, sticky=N+S) window.mainloop() if __name__ == '__main__': main()