I'm currently working on a project in Python 2.6.1 using the Tkinter interface, and being new to both Python and Tkinter I've quickly found a problem that keen internet trawling hasn't seemed to help. I'm sure its not a particularly difficult problem or anything, but instead of spending probably many more hours hunting for a solution like usual I thought it makes sense to ask around, because almost certainly someone has had the same problem.
Anyway, I'm trying the load the same image from file multiple times and packing each loaded instance into a frame. The idea is to make a "bar" consisting of my image repeated, a bar that can shrink or grow to match the width of the Listbox beneath it by loading more or less instances of the image inside (I also thought breaking the bar into a repeated 5-pixel wide image would be faster than loading a single say 100-pixel wide image - is this correct?)
I can successfully load the image, but unfortunately there seems to be an automatically added padding of around 5 pixels on either side of each instance of the image, which kills the bar effect obviously.
Here's the rough code:
#create heading, using expandable heading background self.heading_frame = tk.Frame(self, \ width = list_width, \ height = list_height) self.heading_frame.grid(row = 0, \ column = 1, \ columnspan = 2, \ pady = 10, \ sticky = 'ws') #open background image for the heading bar raw_savvy_bar1 = Image.open("savvy_bar1.png") savvy_bar1 = ImageTk.PhotoImage(raw_savvy_bar1) #calculate the number of times the image must be repeated #for the bar to have width equal to the Listbox beneath num_reps = int(floor(list_width / raw_savvy_bar1.size)) for rep in range(num_reps): heading = tk.Label(self.heading_frame, \ image = savvy_bar1) heading.image = savvy_bar1 heading.pack(side = 'left', anchor = 'w')
I'm using the Python Imaging Library (PIL) (as you can see). Right now this code is inside a subclassed frame class which I use as the definition of my application, but I have tried replicating the problem in different contexts to the same result. Other widgets or other widgets in different contexts do not seem to have the same problem (I successfully packed two Button widgets side by side with no padding at all).
So anyway help would be much appreciated