472,958 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Insert image to a List box

I run the following code and got the error (I put a .gif file on the desktop)
Traceback (most recent call last):
File "11.py", line 25, in <module>
for gifname in os.listdir(dirpath):
OSError: [Errno 2] No such file or directory: '.\\Desktop\\'

import os
import Tkinter

root = Tkinter.Tk()
L = Tkinter.Listbox(selectmode=Tkinter.SINGLE)
gifsdict = {}

dirpath = '.\\Desktop\\'
for gifname in os.listdir(dirpath):
if not gifname[0].isdigit():
continue
gifpath = os.path.join(dirpath, gifname)
gif = Tkinter.PhotoImage(file=gifpath)
gifsdict[gifname] = gif
L.insert(Tkinter.END, gifname)

L.pack()
img = Tkinter.Label()
img.pack()
def list_entry_clicked(*ignore):
imgname = L.get(L.curselection()[0])
img.config(image=gifsdict[imgname])
L.bind('<ButtonRelease-1>', list_entry_clicked)
root.mainloop()
Nov 15 '07 #1
1 5677
Thanks a lot for your patience.
I put the gif file to a folder called fig in my desktop.
dirpath = './fig'
still got error:

Traceback (most recent call last):
File "11.py", line 238, in <module>
img.config(image=gifsdict[imgname])
NameError: name 'imgname' is not defined
You should reply to the python list. That way everyone gets the
benefit of your questions.

The problem is here:
Expand|Select|Wrap|Line Numbers
  1. def list_entry_clicked(*ignore):
  2. imgname = L.get(L.curselection()[0])
  3. img.config(image=gifsdict[imgname])
  4. L.bind('<ButtonRelease-1>', list_entry_clicked)
  5.  
I think the main problem is that the line
`img.config(image=gifsdict[imgname])' is supposed to be part of
`list_entry_clicked' and it isn't.

What you want to do (maybe? I made some assumptions):
Expand|Select|Wrap|Line Numbers
  1. def list_entry_clicked(*ignore):
  2. imgname = L.get(L.curselection()[0])
  3. img.config(image=gifsdict[imgname])
  4.  
  5. L.bind('<ButtonRelease-1>', list_entry_clicked)
  6.  
That _should_ work, but it is untested.

Matt
Nov 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: EricRobineau | last post by:
hello I have a DB with many inter-related tables (MySQL) My main table called "content" has almost only foreign keys (integers) some have a 3 level relation (ex: content->city->region->country) ...
2
by: E. Paul Wileyto | last post by:
Can anyone help. I would like to create a table that contains references to a series of JPG files, so that I can view each image and related data in a form, page by page. It seems that the only...
0
by: PF Melamed | last post by:
Hi.. We are writing a prog in C# (.net) we want to use the aximgadmin object to insert a tiff file to another one. in WB we have : dest.image = "Dest.tif" source.image = "Source.tif" 'the...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
6
by: SandySears | last post by:
I am trying to use a stored procedure to insert a record using VS 2005, VB and SQL Server Express. The code runs without errors or exceptions, and returns the new identifer in the output...
3
by: JpMaxMan | last post by:
Greetings - I have found very little definitive information on this. From what I can surmize at some point the ability to update an image in the gridview using the imagefield was removed from the...
0
by: None | last post by:
Hi, I'm using DataGridView in my Windows Forms project. I need to know how we can insert an image into the specified cell . I tried with the following code.
8
by: andrewtayloruk | last post by:
Hi i was wondering if anyone could help.... I have made a little script that puts whatever a user enters into a mysql database. As well as the forms my script has an image input that uploads an image...
1
by: Asking | last post by:
Hi all, I want to insert an image any location (x, y) on RichTextBox or PictureBox (or any on component supported drawing too). Can I do this? or How can I do this, please show me a way ? ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.