Python Tkinter.PhotoImage() Examples

The following are 30 code examples of Tkinter.PhotoImage(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Tkinter , or try the search function .
Example #1
Source File: nemo_app.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, image, initialField, initialText):
        frm = tk.Frame(root)
        frm.config(background="white")
        self.image = tk.PhotoImage(format='gif',data=images[image.upper()])
        self.imageDimmed = tk.PhotoImage(format='gif',data=images[image])
        self.img = tk.Label(frm)
        self.img.config(borderwidth=0)
        self.img.pack(side = "left")
        self.fld = tk.Text(frm, **fieldParams)
        self.initScrollText(frm,self.fld,initialField)
        frm = tk.Frame(root)
        self.txt = tk.Text(frm, **textParams)
        self.initScrollText(frm,self.txt,initialText)
        for i in range(2):
            self.txt.tag_config(colors[i], background = colors[i])
            self.txt.tag_config("emph"+colors[i], foreground = emphColors[i]) 
Example #2
Source File: test_images.py    From oss-ftp with MIT License 6 votes vote down vote up
def check_create_from_data(self, ext):
        testfile = support.findfile('python.' + ext, subdir='imghdrdata')
        with open(testfile, 'rb') as f:
            data = f.read()
        image = tkinter.PhotoImage('::img::test', master=self.root,
                                   data=data)
        self.assertEqual(str(image), '::img::test')
        self.assertEqual(image.type(), 'photo')
        self.assertEqual(image.width(), 16)
        self.assertEqual(image.height(), 16)
        self.assertEqual(image['data'], data if self.wantobjects
                                        else data.decode('latin1'))
        self.assertEqual(image['file'], '')
        self.assertIn('::img::test', self.root.image_names())
        del image
        self.assertNotIn('::img::test', self.root.image_names()) 
Example #3
Source File: ImageTk.py    From lambda-text-extractor with Apache License 2.0 6 votes vote down vote up
def _show(image, title):
    """Helper for the Image.show method."""

    class UI(tkinter.Label):
        def __init__(self, master, im):
            if im.mode == "1":
                self.image = BitmapImage(im, foreground="white", master=master)
            else:
                self.image = PhotoImage(im, master=master)
            tkinter.Label.__init__(self, master, image=self.image,
                                   bg="black", bd=0)

    if not tkinter._default_root:
        raise IOError("tkinter not initialized")
    top = tkinter.Toplevel()
    if title:
        top.title(title)
    UI(top, image).pack() 
Example #4
Source File: ImageTk.py    From CNCGToolKit with MIT License 6 votes vote down vote up
def _show(image, title):

    class UI(Tkinter.Label):
        def __init__(self, master, im):
            if im.mode == "1":
                self.image = BitmapImage(im, foreground="white", master=master)
            else:
                self.image = PhotoImage(im, master=master)
            Tkinter.Label.__init__(self, master, image=self.image,
                bg="black", bd=0)

    if not Tkinter._default_root:
        raise IOError, "tkinter not initialized"
    top = Tkinter.Toplevel()
    if title:
        top.title(title)
    UI(top, image).pack() 
Example #5
Source File: ImageTk.py    From lambda-text-extractor with Apache License 2.0 6 votes vote down vote up
def _show(image, title):
    """Helper for the Image.show method."""

    class UI(tkinter.Label):
        def __init__(self, master, im):
            if im.mode == "1":
                self.image = BitmapImage(im, foreground="white", master=master)
            else:
                self.image = PhotoImage(im, master=master)
            tkinter.Label.__init__(self, master, image=self.image,
                                   bg="black", bd=0)

    if not tkinter._default_root:
        raise IOError("tkinter not initialized")
    top = tkinter.Toplevel()
    if title:
        top.title(title)
    UI(top, image).pack() 
Example #6
Source File: test_images.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_write(self):
        image = self.create()
        self.addCleanup(support.unlink, support.TESTFN)

        image.write(support.TESTFN)
        image2 = tkinter.PhotoImage('::img::test2', master=self.root,
                                    format='ppm',
                                    file=support.TESTFN)
        self.assertEqual(str(image2), '::img::test2')
        self.assertEqual(image2.type(), 'photo')
        self.assertEqual(image2.width(), 16)
        self.assertEqual(image2.height(), 16)
        self.assertEqual(image2.get(0, 0), image.get(0, 0))
        self.assertEqual(image2.get(15, 8), image.get(15, 8))

        image.write(support.TESTFN, format='gif', from_coords=(4, 6, 6, 9))
        image3 = tkinter.PhotoImage('::img::test3', master=self.root,
                                    format='gif',
                                    file=support.TESTFN)
        self.assertEqual(str(image3), '::img::test3')
        self.assertEqual(image3.type(), 'photo')
        self.assertEqual(image3.width(), 2)
        self.assertEqual(image3.height(), 3)
        self.assertEqual(image3.get(0, 0), image.get(4, 6))
        self.assertEqual(image3.get(1, 2), image.get(5, 8)) 
Example #7
Source File: ImageTk.py    From teleport with Apache License 2.0 6 votes vote down vote up
def _show(image, title):
    """Helper for the Image.show method."""

    class UI(tkinter.Label):
        def __init__(self, master, im):
            if im.mode == "1":
                self.image = BitmapImage(im, foreground="white", master=master)
            else:
                self.image = PhotoImage(im, master=master)
            tkinter.Label.__init__(self, master, image=self.image,
                                   bg="black", bd=0)

    if not tkinter._default_root:
        raise IOError("tkinter not initialized")
    top = tkinter.Toplevel()
    if title:
        top.title(title)
    UI(top, image).pack() 
Example #8
Source File: test_images.py    From PokemonGo-DesktopMap with MIT License 6 votes vote down vote up
def check_create_from_data(self, ext):
        testfile = support.findfile('python.' + ext, subdir='imghdrdata')
        with open(testfile, 'rb') as f:
            data = f.read()
        image = tkinter.PhotoImage('::img::test', master=self.root,
                                   data=data)
        self.assertEqual(str(image), '::img::test')
        self.assertEqual(image.type(), 'photo')
        self.assertEqual(image.width(), 16)
        self.assertEqual(image.height(), 16)
        self.assertEqual(image['data'], data if self.wantobjects
                                        else data.decode('latin1'))
        self.assertEqual(image['file'], '')
        self.assertIn('::img::test', self.root.image_names())
        del image
        self.assertNotIn('::img::test', self.root.image_names()) 
Example #9
Source File: ImageTk.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _show(image, title):
    """Helper for the Image.show method."""

    class UI(tkinter.Label):
        def __init__(self, master, im):
            if im.mode == "1":
                self.image = BitmapImage(im, foreground="white", master=master)
            else:
                self.image = PhotoImage(im, master=master)
            tkinter.Label.__init__(self, master, image=self.image,
                                   bg="black", bd=0)

    if not tkinter._default_root:
        raise IOError("tkinter not initialized")
    top = tkinter.Toplevel()
    if title:
        top.title(title)
    UI(top, image).pack() 
Example #10
Source File: components.py    From SEM with MIT License 6 votes vote down vote up
def __init__(self, root, main_window, button_opt):
        ttk.Frame.__init__(self, root)
        
        self.root = root
        self.main_window = main_window
        self.current_files = None
        self.button_opt = button_opt
        
        # define options for opening or saving a file
        self.file_opt = options = {}
        options['defaultextension'] = '.txt'
        options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        options['initialdir'] = os.path.expanduser("~")
        options['parent'] = root
        options['title'] = 'Select files to annotate.'
        
        self.file_selector_button = ttk.Button(self.root, text=u"select file(s)", command=self.filenames)
        self.label = ttk.Label(self.root, text=u"selected file(s):")
        self.fa_search = tkinter.PhotoImage(file=os.path.join(self.main_window.resource_dir, "images", "fa_search_24_24.gif"))
        self.file_selector_button.config(image=self.fa_search, compound=tkinter.LEFT)
        
        self.scrollbar = ttk.Scrollbar(self.root)
        self.selected_files = tkinter.Listbox(self.root, yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.selected_files.yview) 
Example #11
Source File: test_images.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def create(self):
        return tkinter.PhotoImage('::img::test', master=self.root,
                                  file=self.testfile) 
Example #12
Source File: test_widgets.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def test_image(self):
        widget = self.create()
        image = tkinter.PhotoImage(master=self.root, name='image1')
        self.checkParam(widget, 'image', image, conv=str)
        errmsg = 'image "spam" doesn\'t exist'
        with self.assertRaises(tkinter.TclError) as cm:
            widget['image'] = 'spam'
        if errmsg is not None:
            self.assertEqual(str(cm.exception), errmsg)
        with self.assertRaises(tkinter.TclError) as cm:
            widget.configure({'image': 'spam'})
        if errmsg is not None:
            self.assertEqual(str(cm.exception), errmsg) 
Example #13
Source File: test_images.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def test_configure_file(self):
        image = tkinter.PhotoImage('::img::test', master=self.root)
        self.assertEqual(image['file'], '')
        image.configure(file=self.testfile)
        self.assertEqual(image['file'], self.testfile)
        self.assertEqual(image.width(), 16)
        self.assertEqual(image.height(), 16) 
Example #14
Source File: test_images.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def check_create_from_file(self, ext):
        testfile = support.findfile('python.' + ext, subdir='imghdrdata')
        image = tkinter.PhotoImage('::img::test', master=self.root,
                                   file=testfile)
        self.assertEqual(str(image), '::img::test')
        self.assertEqual(image.type(), 'photo')
        self.assertEqual(image.width(), 16)
        self.assertEqual(image.height(), 16)
        self.assertEqual(image['data'], '')
        self.assertEqual(image['file'], testfile)
        self.assertIn('::img::test', self.root.image_names())
        del image
        self.assertNotIn('::img::test', self.root.image_names()) 
Example #15
Source File: test_images.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def test_configure_format(self):
        image = tkinter.PhotoImage('::img::test', master=self.root)
        self.assertEqual(image['format'], '')
        image.configure(file=self.testfile, format='gif')
        self.assertEqual(image['format'], ('gif',) if self.wantobjects
                                          else 'gif')
        self.assertEqual(image.width(), 16)
        self.assertEqual(image.height(), 16) 
Example #16
Source File: ImageTk.py    From lambda-text-extractor with Apache License 2.0 5 votes vote down vote up
def __str__(self):
        """
        Get the Tkinter photo image identifier.  This method is automatically
        called by Tkinter whenever a PhotoImage object is passed to a Tkinter
        method.

        :return: A Tkinter photo image identifier (a string).
        """
        return str(self.__photo) 
Example #17
Source File: ImageTk.py    From lambda-text-extractor with Apache License 2.0 5 votes vote down vote up
def __init__(self, image=None, size=None, **kw):

        # Tk compatibility: file or data
        if image is None:
            image = _get_image_from_kw(kw)

        if hasattr(image, "mode") and hasattr(image, "size"):
            # got an image instead of a mode
            mode = image.mode
            if mode == "P":
                # palette mapped data
                image.load()
                try:
                    mode = image.palette.mode
                except AttributeError:
                    mode = "RGB"  # default
            size = image.size
            kw["width"], kw["height"] = size
        else:
            mode = image
            image = None

        if mode not in ["1", "L", "RGB", "RGBA"]:
            mode = Image.getmodebase(mode)

        self.__mode = mode
        self.__size = size
        self.__photo = tkinter.PhotoImage(**kw)
        self.tk = self.__photo.tk
        if image:
            self.paste(image) 
Example #18
Source File: ImageTk.py    From lambda-text-extractor with Apache License 2.0 5 votes vote down vote up
def __init__(self, image=None, size=None, **kw):

        # Tk compatibility: file or data
        if image is None:
            image = _get_image_from_kw(kw)

        if hasattr(image, "mode") and hasattr(image, "size"):
            # got an image instead of a mode
            mode = image.mode
            if mode == "P":
                # palette mapped data
                image.load()
                try:
                    mode = image.palette.mode
                except AttributeError:
                    mode = "RGB"  # default
            size = image.size
            kw["width"], kw["height"] = size
        else:
            mode = image
            image = None

        if mode not in ["1", "L", "RGB", "RGBA"]:
            mode = Image.getmodebase(mode)

        self.__mode = mode
        self.__size = size
        self.__photo = tkinter.PhotoImage(**kw)
        self.tk = self.__photo.tk
        if image:
            self.paste(image) 
Example #19
Source File: test_images.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def test_configure_width_height(self):
        image = tkinter.PhotoImage('::img::test', master=self.root)
        self.assertEqual(image['width'], '0')
        self.assertEqual(image['height'], '0')
        image.configure(width=20)
        image.configure(height=10)
        self.assertEqual(image['width'], '20')
        self.assertEqual(image['height'], '10')
        self.assertEqual(image.width(), 20)
        self.assertEqual(image.height(), 10) 
Example #20
Source File: GUI.py    From Scoary with GNU General Public License v3.0 5 votes vote down vote up
def initialize_logo(self):
        """
        Initialize logo
        """
        photo=Tkinter.PhotoImage(data=self.Photobase64())
        self.logocanvas.img = photo
        self.logocanvas.create_image(0,0,anchor='nw',image=photo) 
Example #21
Source File: ImageTk.py    From CNCGToolKit with MIT License 5 votes vote down vote up
def __str__(self):
        return str(self.__photo)

##
# Copies the contents of a PhotoImage to a PIL image memory. 
Example #22
Source File: ImageTk.py    From CNCGToolKit with MIT License 5 votes vote down vote up
def __del__(self):
        name = self.__photo.name
        self.__photo.name = None
        try:
            self.__photo.tk.call("image", "delete", name)
        except:
            pass # ignore internal errors

    ##
    # Get the Tkinter photo image identifier.  This method is
    # automatically called by Tkinter whenever a PhotoImage object is
    # passed to a Tkinter method.
    #
    # @return A Tkinter photo image identifier (a string). 
Example #23
Source File: ImageTk.py    From CNCGToolKit with MIT License 5 votes vote down vote up
def __init__(self, image=None, size=None, **kw):

        # Tk compatibility: file or data
        if image is None:
            if kw.has_key("file"):
                image = Image.open(kw["file"])
                del kw["file"]
            elif kw.has_key("data"):
                from StringIO import StringIO
                image = Image.open(StringIO(kw["data"]))
                del kw["data"]

        if hasattr(image, "mode") and hasattr(image, "size"):
            # got an image instead of a mode
            mode = image.mode
            if mode == "P":
                # palette mapped data
                image.load()
                try:
                    mode = image.palette.mode
                except AttributeError:
                    mode = "RGB" # default
            size = image.size
            kw["width"], kw["height"] = size
        else:
            mode = image
            image = None

        if mode not in ["1", "L", "RGB", "RGBA"]:
            mode = Image.getmodebase(mode)

        self.__mode = mode
        self.__size = size
        self.__photo = apply(Tkinter.PhotoImage, (), kw)
        self.tk = self.__photo.tk
        if image:
            self.paste(image) 
Example #24
Source File: ImageTk.py    From CNCGToolKit with MIT License 5 votes vote down vote up
def _pilbitmap_check():
    global _pilbitmap_ok
    if _pilbitmap_ok is None:
        try:
            im = Image.new("1", (1,1))
            Tkinter.BitmapImage(data="PIL:%d" % im.im.id)
            _pilbitmap_ok = 1
        except Tkinter.TclError:
            _pilbitmap_ok = 0
    return _pilbitmap_ok

# --------------------------------------------------------------------
# PhotoImage

##
# Creates a Tkinter-compatible photo image.  This can be used
# everywhere Tkinter expects an image object.  If the image is an RGBA
# image, pixels having alpha 0 are treated as transparent. 
Example #25
Source File: turtle.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _image(filename):
        """return an image object containing the
        imagedata from a gif-file named filename.
        """
        return TK.PhotoImage(file=filename) 
Example #26
Source File: turtle.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def _blankimage():
        """return a blank image object
        """
        img = TK.PhotoImage(width=1, height=1)
        img.blank()
        return img 
Example #27
Source File: Controls.py    From Python-Media-Player with Apache License 2.0 5 votes vote down vote up
def create_control_panel(self):
        frame=Tkinter.LabelFrame(self.root)
        frame.pack(expand='yes',fill='x',side='top')
        add_fileicon=Tkinter.PhotoImage(file="../Icons/add_file.gif")
        add_directoryicon=Tkinter.PhotoImage(file="../Icons/add_directory.gif")
        exiticon=Tkinter.PhotoImage(file="../Icons/exit.gif")
        playicon=Tkinter.PhotoImage(file="../Icons/play.gif")
        pauseicon=Tkinter.PhotoImage(file="../Icons/pause.gif")
        stopicon=Tkinter.PhotoImage(file="../Icons/stop.gif")
        rewindicon=Tkinter.PhotoImage(file="../Icons/rewind.gif")
        fast_forwardicon=Tkinter.PhotoImage(file="../Icons/fast_forward.gif")
        previous_trackicon=Tkinter.PhotoImage(file="../Icons/previous_track.gif")
        next_trackicon=Tkinter.PhotoImage(file="../Icons/next_track.gif")
        self.muteicon=Tkinter.PhotoImage(file="../Icons/mute.gif")
        self.unmuteicon=Tkinter.PhotoImage(file="../Icons/unmute.gif")
        delete_selectedicon=Tkinter.PhotoImage(file="../Icons/delete_selected.gif")

        list_file=[
            (playicon,'self.play'),
            (pauseicon,'self.pause'),
            (stopicon,'self.stop'),
            (previous_trackicon,'self.previous'),
            (rewindicon,'self.rewind'),
            (fast_forwardicon,'self.fast'),
            (next_trackicon,'self.Next'),]
        for i,j in list_file:
            storeobj=ttk.Button(frame, image=i,command=eval(j))
            storeobj.pack(side='left')
            storeobj.image=i
        self.volume_label=Tkinter.Button(frame,image=self.unmuteicon)
        self.volume_label.image=self.unmuteicon
        
        volume=ttk.Scale(frame,from_=Volume_lowest_value, to=Volume_highest_value ,variable=self.var, command=self.update_volume)
        volume.pack(side='right', padx=10, )
        self.volume_label.pack(side='right')
        return 
Example #28
Source File: ListPanel.py    From Python-Media-Player with Apache License 2.0 5 votes vote down vote up
def create_song_list_panel(self):
        # Creating Picture Canvas as Background
        background=Tkinter.PhotoImage(file="../Icons/background.gif")
        mainframe=Tkinter.Canvas(self.root)
        mainframe.pack(side='top', expand='yes', fill='both')
        mainframe.image=background
        mainframe.create_image(0, 0, anchor="nw", image=background)
        
        frame0=Tkinter.Frame(mainframe)
        frame0.pack(side='top')
        Tkinter.Label(frame0, text='Search : ', bg='skyblue').pack(side='left', expand='yes', fill='x')
        Tkinter.Entry(frame0, textvariable=self.var1).pack(side='left', expand='yes', fill='x')
        frame0.bind_all('<Any-KeyPress>',self.search_song_trigger)
        frame=Tkinter.Frame(mainframe, bg='skyblue')
        frame.pack(side='top')
        self.list_box=Tkinter.Listbox(frame, bg='powderblue', font=list_box_song_list_font, width=list_box_width, height=list_box_height)
        scrollbar=Tkinter.Scrollbar(frame, bg='skyblue')
        scrollbar.pack(side='right',expand='yes',fill='y')
        scrollbar.config(command=self.list_box.yview)
        self.list_box.config(yscrollcommand=scrollbar.set)
        self.list_box.pack(expand='yes',fill='both',side='right')
        frame1=Tkinter.Frame(mainframe, bg='blue')
        frame1.pack(side='top', expand='yes',fill='x')
        add_fileicon=Tkinter.PhotoImage(file="../Icons/add_file.gif")
        add_directoryicon=Tkinter.PhotoImage(file="../Icons/add_directory.gif")
        list_file=[
        (add_fileicon,'self.ask_for_play_song_direct'),
        (add_directoryicon,'self.ask_for_directory'),
        ]
        for i,j in list_file:
                storeobj=Tkinter.Button(frame1, image=i, command=eval(j), bg='blue')
                storeobj.pack(side='left')
                storeobj.image=i
        self.list_box.bind('<Double-Button-1>',self.play_on_click)
        return self.update_list_box_songs() 
Example #29
Source File: DisplayPanel.py    From Python-Media-Player with Apache License 2.0 5 votes vote down vote up
def create_console(self):
        self.back_time_label=Tkinter.PhotoImage(file="../Icons/background.gif")
        # consoleframe=Tkinter.LabelFrame(self.root, text='Display Panel', bg='aqua')
        # consoleframe.pack(side='top', expand='yes', fill='x')
        self.canvas=Tkinter.Canvas(self.root, width=400, height=100, bg='skyblue')
        self.canvas.pack()
        self.canvas.image=self.back_time_label
        self.canvas.create_image(0, 0, anchor="nw", image=self.back_time_label)
        self.time_display=self.canvas.create_text(10, 25, anchor="nw", fill='cornsilk', font=Digital_Clock_Font_Setting, text='0:00:00')
        self.song_display=self.canvas.create_text(220,40, anchor="nw", fill='cornsilk', font=Songs_playing_Font_Setting, text='Nothing For Playing')
        self.song_duration=self.canvas.create_text(220,65, anchor="nw", fill='cornsilk', font=duration_time_Font_Setting, text='[0:00:00]')        
        return 
Example #30
Source File: juegochozas.py    From Tutoriales_juegos_Python with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        self.imagen_fondo = PhotoImage(file="Jungle_small_2.gif")
        self.imagen_choza = PhotoImage(file="Hut_small_2.gif")

        self.ancho_choza = 60
        self.alto_choza = 140
        self.container = parent

        self.Chozas = []
        self.result = ""

        self.ocupar_chozas()

        self.setup()