tkinter: using scrollbars on a canvas

Your scrollbars need to have the Frame as a parent, not the Canvas: from tkinter import * root=Tk() frame=Frame(root,width=300,height=300) frame.pack(expand=True, fill=BOTH) #.grid(row=0,column=0) canvas=Canvas(frame,bg=’#FFFFFF’,width=300,height=300,scrollregion=(0,0,500,500)) hbar=Scrollbar(frame,orient=HORIZONTAL) hbar.pack(side=BOTTOM,fill=X) hbar.config(command=canvas.xview) vbar=Scrollbar(frame,orient=VERTICAL) vbar.pack(side=RIGHT,fill=Y) vbar.config(command=canvas.yview) canvas.config(width=300,height=300) canvas.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set) canvas.pack(side=LEFT,expand=True,fill=BOTH) root.mainloop() The reason why this works is due to how pack works. By default it will attempt to shrink (or grow) a … Read more

Disable / Enable Button in TKinter

A Tkinter Button has three states : active, normal, disabled. You set the state option to disabled to gray out the button and make it unresponsive. It has the value active when the mouse is over it and the default is normal. Using this you can check for the state of the button and take … Read more

How to attach a Scrollbar to a Text widget?

Tkinter has three geometry managers: pack, grid, and place. Pack and grid are usually recommended over place. You can use the grid manager’s row and column options to position the Scrollbar next to the Text widget. Set the Scrollbar widget’s command option to the Text’s yview method. scrollb = tkinter.Scrollbar(…, command=txt.yview) Set the Text widget’s … Read more

How do I run unittest on a Tkinter app?

Bottom line: pump the events with the below code after an action that causes a UI event, before a later action that needs the effect of that event. IPython provides an elegant solution without threads it its gui tk magic command implementation that’s located in terminal/pt_inputhooks/tk.py. Instead of root.mainloop(), it runs root.dooneevent() in a loop, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)