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

How to bind events to Canvas items?

To interact with objects contained in a Canvas object you need to use tag_bind() which has this format: tag_bind(item, event=None, callback=None, add=None) The item parameter can be either a tag or an id. Here is an example to illustrate the concept: from tkinter import * def onObjectClick(event): print(‘Got object click’, event.x, event.y) print(event.widget.find_closest(event.x, event.y)) root … Read more

How do I remove the light grey border around my Canvas widget?

Section 6.8 Why doesn’t the canvas seem to start at 0,0? of the Tk Usage FAQ describes the phenomenon. I was able to eliminate the border artefact with slight changes to the posted source… Change this: w = Canvas(master, width=150, height=40, bd=0, relief=”ridge”) w.pack() to: w = Canvas(master, width=150, height=40, bd=0, highlightthickness=0, relief=”ridge”) w.pack() and … Read more

Why does Tkinter image not show up if created in a function?

The variable photo is a local variable which gets garbage collected after the class is instantiated. Save a reference to the photo, for example: self.photo = tkinter.PhotoImage(…) If you do a Google search on “tkinter image doesn’t display”, the first result is this: Why do my Tkinter images not appear? (The FAQ answer is currently … Read more

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