473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

compatible image type

hi
in my application a file selection by user returns a pathname string
like F:/images/png/my.png or F:/docs/text/somedoc.txt ....etc.
I can get the extension using
extn=string.split(os.path.basename(pathname),'.' )[1]

then later on i want to create a Photoimage using

ImageTk.PhotoImage(file=pathname) and display it on a canvas.

the extn can be anything ..even zip or bat ,doc whatever depending on
user selection...I want to put someway to raise an error message to
the user if he selects a file with extension not of a compatible image
type for PhotoImage.How should i do this? should i check 'extn' to a
list of compatible image type extensions(something like
[''jpg','jpeg','png','gif'...] ) or is there a better way?

gordon
Jul 4 '08 #1
2 1351
On Fri, 04 Jul 2008 01:15:30 -0700, gordon wrote:

then later on i want to create a Photoimage using

ImageTk.PhotoImage(file=pathname) and display it on a canvas.

the extn can be anything ..even zip or bat ,doc whatever depending on
user selection...I want to put someway to raise an error message to
the user if he selects a file with extension not of a compatible image
type for PhotoImage.How should i do this? should i check 'extn' to a
list of compatible image type extensions(something like
[''jpg','jpeg','png','gif'...] ) or is there a better way?
Just catch the exception raised by `PhotoImage` if a non compatible file
was selected!?

Ciao,
Marc 'BlackJack' Rintsch
Jul 4 '08 #2
gordon wrote:
hi
in my application a file selection by user returns a pathname string
like F:/images/png/my.png or F:/docs/text/somedoc.txt ....etc.
I can get the extension using
extn=string.split(os.path.basename(pathname),'.' )[1]

then later on i want to create a Photoimage using

ImageTk.PhotoImage(file=pathname) and display it on a canvas.

the extn can be anything ..even zip or bat ,doc whatever depending on
user selection...I want to put someway to raise an error message to
the user if he selects a file with extension not of a compatible image
type for PhotoImage.How should i do this? should i check 'extn' to a
list of compatible image type extensions(something like
[''jpg','jpeg','png','gif'...] ) or is there a better way?

gordon
You do know that there is a method for getting extensions easily?

extn = os.path.splitext(pathname)[1]

Note: It does include the '.' separator (e.g. it returns .txt) but that's easy
to handle.

If you just catch the exception (as Mark suggested), you don't even have to look
at the extension.

-Larry
Jul 4 '08 #3

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

Similar topics

9
by: Pierre Tremblay | last post by:
Hi! I am trying to display an image in my html document. The document contains the following line: <td class="Input"><img...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
5
by: Leif K-Brooks | last post by:
I need to do some simple image editing (pretty much just scaling) in a GPLed program. Unfortunatly, both of the Python libraries for image editing that I found (gdmodule and PIL) are under the...
6
by: MLH | last post by:
For instance, is it common practice to drop a PDF image onto an Access 97 form as a 'background', superimposing textbox data fields over it as a fill- in-the-blank type form? Same for reports?...
9
by: christer-sandberg | last post by:
When I typecast a function and call it trough the casted pointer (se code below) I get the warnings: warning: function called through a non-compatible type if this code is reached, the program...
0
by: M K | last post by:
Okay, here is my message: The base class includes the field 'Preview1', but its type (ICUser.uCtrlPreview) is not compatible with the type of control (ASP.previewImg_ascx). What I am trying to...
5
by: max | last post by:
Dear all, I did the following analysis to conclude that the following pointer types are not compatible. Please let me know If my analysis and interpretation of the C standard are correct: ...
7
by: Inny | last post by:
Hello again, Im using the code below in a child page (popup), the images are called from the parent page. When the changer is running, the child page goes white between images. I realise this is...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.