Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8306805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:24:11+00:00 2026-06-08T18:24:11+00:00

Here’s the issue – I’m writing a program that will iterate through a series

  • 0

Here’s the issue –

I’m writing a program that will iterate through a series of image manipulations – both effecting the whole image as well as just portions of the image. I need to demonstrate these changes to the user (myself) so I can see what’s going wrong with my manipulations as they take place.

I originally tried to use PIL and Tkinter to do this – but I couldn’t even load an image into the GUI – here’s a bit of code formed from the corners of the web, via many google searches:

from Tkinter import *
import Image, ImageDraw, ImageTk
import time

class Test(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.c = Canvas(self, width=574, height=431, bg="red")
        self.c.pack()
        Button(self, text="Process", command=self.procImg).pack()
        Button(self, text="Quit", command=self.quit).pack()
    def procImg(self):
        t = time.time()
        self.flashImg = Image.open("./in_img/resize.bmp")
        #self.flashImg = flashImg.resize((574, 431))
        self.flashImg = self.flashImg.convert("L")
        #self.photo = ImageTk.BitmapImage(flashImg)
        self.c.photo = ImageTk.PhotoImage(self.flashImg)
        self.c.create_image(574, 431, anchor=NW, image=self.c.photo)
        self.c.create_rectangle(50, 50, 100, 100, fill="blue")
        self.update()
        print time.time()-t

t = Test()
t.pack()
t.mainloop()

So the above code is pretty bad, I know – but I wanted to post something to prove that I have at least been working at this.

Can anyone suggest to me a new way of approaching this problem using Python? I’d rather not learn a different language – I’m new to the Tkinter library so if something else is better suited for this, I have no issues learning a new library.

Also, FYI, the “resize.bmp” image is a resized .JPG from a digital camera. I tried that one too and it didn’t work – I really need to find a way to flash bitmaps from memory to the screen in a GUI so I can adjust parameters as the processing is going on.

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:24:13+00:00Added an answer on June 8, 2026 at 6:24 pm

    The image is probably there. It’s just not visible.

    Instead of :

    self.c.create_image(574, 431, anchor=NW, image=self.c.photo)
    

    try :

    self.c.create_image(0, 0, anchor=NW, image=self.c.photo)
    

    Also, if you keep a reference to the canvas image item, you can swap different images in and out.

    eg. (self.canvasItem) below :

    from Tkinter import * 
    from PIL import Image, ImageTk, ImageDraw, ImageOps, ImageEnhance
    
    
    class ImageButcher(Tk):
        def __init__(self):
            Tk.__init__(self)
    
            #create ui
            f = Frame(self, bd=2)
    
            self.colour = StringVar(self)
            self.colourMenu = OptionMenu(f, self.colour,
                                         *('red','green','blue','white'))
            self.colourMenu.config(width=5)
            self.colour.set('red')
            self.colourMenu.pack(side='left')
    
            self.rectangleButton = Button(f, text='Rectangle',
                                        command=self.draw_rectangle)
            self.rectangleButton.pack(side='left')
    
            self.brightenButton = Button(f, text='Brighten',
                                        command=self.on_brighten)
            self.brightenButton.pack(side='left')
    
            self.mirrorButton = Button(f, text='Mirror',
                                        command=self.on_mirror)
            self.mirrorButton.pack(side='left')
            f.pack(fill='x')
    
            self.c = Canvas(self, bd=0, highlightthickness=0,
                            width=100, height=100)
            self.c.pack(fill='both', expand=1)
    
            #load image
            im = Image.open('IMG_1584.JPG')
            im.thumbnail((512,512))
    
            self.tkphoto = ImageTk.PhotoImage(im)
            self.canvasItem = self.c.create_image(0,0,anchor='nw',image=self.tkphoto)
            self.c.config(width=im.size[0], height=im.size[1])
    
            self.img = im
            self.temp = im.copy() # 'working' image
    
        def display_image(self, aImage):
            self.tkphoto = pic = ImageTk.PhotoImage(aImage)
            self.c.itemconfigure(self.canvasItem, image=pic)
    
        def on_mirror(self):
            im = ImageOps.mirror(self.temp)
            self.display_image(im)
            self.temp = im
    
        def on_brighten(self):
            brightener = ImageEnhance.Brightness(self.temp)
            self.temp = brightener.enhance(1.1) # +10%
            self.display_image(self.temp)
    
        def draw_rectangle(self):
            bbox = 9, 9, self.temp.size[0] - 11, self.temp.size[1] - 11        
            draw = ImageDraw.Draw(self.temp)
            draw.rectangle(bbox, outline=self.colour.get())
            self.display_image(self.temp)
    
    
    app = ImageButcher()
    app.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the scenario: I'm writing an app that will watch for any changes
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the issue I am having: I have a large query that needs
Here is the scenario. I'm writing my geo-ruby oracle adapter for Ruby On Rails
Here is the problem that I am trying to solve. I have two folders
Here is my program to find all the subsets of given set. To solve
Here's a query that works fine: SELECT rowid as msg_rowid, a, b, c FROM
Here is my code (Say we have a single button on the page that
Here's the flow that I am trying to achieve: 1) User uploads an audio
Here is another spoj problem that asks how to find the number of distinct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.